Comes with a lot of useful stuff ready to go.
Designed for serverless API development with PostgreSQL.
- Flask Smorest
- OpenAPI
- Swagger UI
- Redoc
- Pytest using database subtransactions for test isolation
- Pytest-FactoryBoy for generating sample data for seeding DB and tests.
- Flake8 for linting
- Mypy for type-checking
- Black for formatting
- AWS Lambda integration
- Serverless AWS
- AWS Aurora Serverless Postgres for on-demand Postgresql DB with a data-api query driver (optional).
- Load Flask config from AWS Secrets Manager
- Flask-Migrate for DB migrations with alembic and Flask CLI
- Poetry for dependency management
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python # poetry
npm i -g serverless
npx sls install --url https://github.com/jetbridge/sls-flask --name myapp
cd myapp
make init # install dependencies and initialize project, database
poetry shell # activate python virtual environment
poetry install # install dependencies
flask # CLI commands
make run # run flask dev server
sls wsgi serve # run flask dev server under serverless
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
make deploy-dev # deploy to AWS and run migrations
make deploy-prd # deploy to AWS and run migrations
Once your flask dev server is running:
- OpenAPI JSON (http://localhost:5000/api/openapi.json)
- Swagger UI (http://localhost:5000/api/swagger)
- ReDoc (http://localhost:5000/api/doc)
There are two options for database access: Aurora Data API or psycopg2/libpq.
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.
Standard Python PostgreSQL database driver. More powerful and efficient but requires enabling lambda VPC networking.
- Uncomment VPC
subnetIds
config inserverless.yml
- Uncomment
- ${file(cloudformation/vpc/lambda.yml)}
resource inclusion inserverless.yml