FastAPI + Amazon API Gateway + AWS Lambda + Cognito - Simple Demo Application
- AWS Account
 - AWS Command Line Tool (CLI) - 
awsaws cli installation guide - AWS Serverless Application Model (SAM) with a command line tool AWS SAM CLI - 
samsam cli installation guide 
- Docker; if you don't have it yet, follow the installation instructions;
 - Docker Compose; refer to the official documentation for the installation guide.
 - Pre-commit; refer to the official documentation for the pre-commit.
 
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
-dto 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
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
For building the stack run:
sam build -t template.yaml
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
For deleting the Stack run:
sam delete --stack-name your-stack-name