Deploys your Python functions in minutes!
This is a template to deploy Python functions rapidly on AWS-Lambda, automated by Terraform.
-
aws-cli and IAM credentials
Basic setup:
- Python code:
- simple code on aws-console or a zip file uploaded to S3 for bigger apps
- every library outside the standard library must be included in the zip file
- you need a handler for Lambda, in this case we use Mangum
- API gateway to trigger the lambda function
- gateway URL used as a proxy to pass requests to the app router
- permissions for gateway: in this case will be public.
- Replaces /src with the code of your Python App
- Downdloads required packages
make install
- Creates a bucket to store state files (
demo-lambda-tfstate
). The bucket name is specify inenv/dev/terrgrunt.hcl
line 46. - Creates a DynamoDB table named
terraform-state-lock-dynamo
with hash key isLockID
and typeS
- Deploys (
dev
environment):
cd ./env/dev/ap-southeast-1
terragrunt run-all apply
- Triggers
login
api
curl --location --request GET 'https://o8fd5nimq0.execute-api.ap-southeast-1.amazonaws.com/dev/users/login'
- Triggers
register
api
curl --location --request POST 'https://o8fd5nimq0.execute-api.ap-southeast-1.amazonaws.com/dev/users/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "John"
}'
Terraform will require the following variables to plan and apply:
AWS_ACCESS_KEY_ID # AWS access key associated with an IAM user or role.
AWS_SECRET_ACCESS_KEY # Secret key associated with the access key. This is essentially the "password" for the access key
AWS_SESSION_TOKEN # Token value that is required if you are using temporary security credentials that you retrieved directly from AWS STS operations