Skip to content
/ sls-flask Public template

Opinionated Flask serverless starter kit

Notifications You must be signed in to change notification settings

jetbridge/sls-flask

Repository files navigation

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

About

Opinionated Flask serverless starter kit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •