Skip to content

FastAPI + Amazon API Gateway + Lambda + Cognito: demo app

Notifications You must be signed in to change notification settings

tivaliy/fastapi-aws-serverless

Repository files navigation

fastapi-aws-serverless

FastAPI + Amazon API Gateway + AWS Lambda + Cognito - Simple Demo Application

Prerequisites

for Deployment:

for Development:

Getting Up and Running Locally with Docker

Create .env file (see .env.example) for more details. Open a terminal at the project root and run the following for local development:

  • Build the Stack:

      $ docker-compose build
    
  • Run the Stack (use -d to run in the detached mode):

      $ docker-compose up
    
  • Run the stack in Debugging mode (with ipdb support):

      $ docker-compose run --rm --service-ports backend
    

By default, service will be available on the following routes:

http://0.0.0.0:8888/docs
http://0.0.0.0:8888/redoc
http://0.0.0.0:8888/openapi.json

Run tests and type checking

Create isolated Python environment virtualenv venv and activate it source venv/bin/activate

Install all necessary dependencies: pip install -r test-requirements.txt

Run tests:

pytest tests -v  # increase verbosity

with coverage report:

pytest --cov=app tests

Run type checking:

mypy app

Build the Stack

For building the stack run:

sam build -t template.yaml

Deploy the Stack

For deploying appropriate Stack (dev, prod) run (with guided prompts):

sam deploy --guided --capabilities CAPABILITY_IAM --config-env dev|prod

For newly created API Gateway endpoint URL see CloudFormation outputs, ex.:

CloudFormation outputs from deployed stack
------------------------------------------------------------------------------------------
Outputs
-----------------------------------------------------------------------------------------
Key                 FastAPI
Description         API Gateway endpoint URL
Value               https://abcdefgh12.execute-api.us-east-1.amazonaws.com/dev
-----------------------------------------------------------------------------------------

Service will be available on the following routes:

https://abcdefgh12.execute-api.us-east-1.amazonaws.com/dev/docs
https://abcdefgh12.execute-api.us-east-1.amazonaws.com/dev/redoc
https://abcdefgh12.execute-api.us-east-1.amazonaws.com/dev/openapi.json

Delete the Stack

For deleting the Stack run:

sam delete --stack-name your-stack-name

About

FastAPI + Amazon API Gateway + Lambda + Cognito: demo app

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published