Deploying fastAPI to AWS Lambda via Amazon API Gateway
May 16, 2020
Alexander Junge
1 minute read

I started experimenting with AWS and as a first tiny project I deployed a fastAPI-based REST API to AWS Lambda, a serverless framework. Amazon API Gateway acts as a front-door to the Lambda instance. The architecture roughly looks like this:

The deployed API is a simplified version of the REST API described in a previous post. My code is available on GitHub.

Using AWS SAM, the deployment works like this:

sam validate
sam build --use-container --debug
sam package --s3-bucket <S3-BUCKET-NAME> --output-template-file out.yml --region eu-west-1
sam deploy --template-file out.yml --stack-name example-stack-name --region eu-west-1 --no-fail-on-empty-changeset --capabilities CAPABILITY_IAM

I found this post very helpful when working on my project. The post describes in a lot more detail which AWS accesses need to be created to make this work - check it out.

A great continuation of my tiny project would be setting up continuous deployment of the API using, for example, GitHub Actions.



comments powered by Disqus