Giter Club home page Giter Club logo

sls-flask's Introduction

Opinionated Serverless Flask

Comes with a lot of useful stuff ready to go.

Designed for serverless API development with PostgreSQL.

Features

Quickstart:

Prerequisites:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python  # poetry
npm i -g serverless

Create Project:

npx sls install --url https://github.com/jetbridge/sls-flask --name myapp
cd myapp
make init  # install dependencies and initialize project, database

Useful Commands:

Python Virtual Environment:

poetry shell  # activate python virtual environment
poetry install  # install dependencies

Run Dev Server:

flask  # CLI commands
make run  # run flask dev server
sls wsgi serve  # run flask dev server under serverless

Database:

Using Postgresql.

createdb TEMPLATE  # create DB
flask db upgrade  # run migrations
flask seed  # populate with sample data
flask db migrate  # generate new migration
flask db  # more migration commands

Deploy:

make deploy-dev   # deploy to AWS and run migrations
make deploy-prd  # deploy to AWS and run migrations

API Documentation:

Once your flask dev server is running:

Database Driver

There are two options for database access: Aurora Data API or psycopg2/libpq.

Aurora Data API

Allows the application to query the database using AWS API calls. Does not require lambdas to be in a VPC, reducing the need for NAT gateways reducing cost and complexity. Has limitations and is somewhat beta.

Psycopg2

Standard Python PostgreSQL database driver. More powerful and efficient but requires enabling lambda VPC networking.

To Enable:
  • Uncomment VPC subnetIds config in serverless.yml
  • Uncomment - ${file(cloudformation/vpc/lambda.yml)} resource inclusion in serverless.yml

sls-flask's People

Contributors

dependabot[bot] avatar gnudeb avatar revmischa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sls-flask's Issues

Dependency issue with Flask-Migrate.

New version of flask-migrate is not backward compatible I suppose and runs fail.

ImportError: cannot import name 'MigrateCommand' from 'flask_migrate'

Usage Tutorial with Example

I am very interested in this particular serverless stack (Serverless Framework + Flask + Aurora), but im strugling to start. If you could provide a tutorial with a concrete example it would be awsome.

swagger UI send request to endpoint without stage and return 403

I managed to create and deploy an application to AWS via this sls-flask service, but the swagger generated doesn't work, after enable the developer tools on Chrome, I found click the execute on swagger, it sends the request to an endpoint with stage, for example:

After "sls deploy -s dev", the output will contain the endpoint which looks like:
https://xxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev

And the swagger page can be accessed via:
https://xxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/api/swagger

But when click the "execute" for api "/api/auth/login", the request will be sent to:
https://xxxxxx.execute-api.ap-southeast-2.amazonaws.com/api/auth/login
and it return "403" {"message":"Forbidden"}

If the request is sent to https://xxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/api/auth/login, it works.

If I change the Blueprint "url_prefix="/api/auth" to "url_prefix="/dev/api/auth", it still doesn't work since now the correct endpoint should be https://xxxxxx.execute-api.ap-southeast-2.amazonaws.com/dev/dev/api/auth/login.

It looks like when sls-flask generate the swagger, it ignores the stage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.