Starter project for python based lambda project.
- FastAPI - Frontend dev with Hot Reload
- API Gateway Integration (+root proxy)
- Local Dev without API Gateway
- Backend with Typings
- Backend Scheduler Support - in a separate function
- Backend SQS Support
- S3 and DynamoDB IAM role
- Pulumi Example
- Shared Lib between Frontend and Backend
- PyTest
- Deploy via Github Action
- Python 3.9
- NodeJS 12+
- Pulumi (to create Queue and DynamoDB)
- AWS Profile set up - https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
# Open `serverless.yml` and change `profile:` and `region:` to match
# Also uncomment API Gateway event
$ npx serverless plugin install -n serverless-python-requirements
# If using pulumi
$ cd pulumi-example
$ npm install
# change pulumi.dev.yaml
config:
aws:region: us-west-2
aws:profile: varokas --- profile
$ pulumi up
$ source .venv/bin/activate
$ uvicorn main:app --reload
$ curl localhost:8000/hello
{"message":"Hello World"}%
# Docs can be found at - http://127.0.0.1:8000/docs
$ npx serverless invoke local -f backend -d '{"name": "TestEvent", "source":"raw", "text": "123"}'
$ npx serverless invoke local -f backend -d '{"name": "TestEvent", "source":"schedule", "time":"2021-12-21T15:34:19Z", "text": "123"}'
$ npx serverless deploy
$ python3 cli.py testevent Hello
$ npx serverless logs -f backend
Go to Settings, Secrets and set the two secret values
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- https://adem.sh/blog/tutorial-fastapi-aws-lambda-serverless
- https://towardsaws.com/local-development-with-serverless-46a219876a67
- https://github.com/tschoffelen/lambda-sample-events
- https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/data_classes/