two-trick-pony-NL / AWSLambdaBackend

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API: A FastAPI CRUD todo App on AWS lambda

I'm experimenting in putting my FastAPI on AWS lambda. Unfortunately the PhotoScavenger API is too big and exceeds the 250MB filesize accepted by lambda. Other than that this repo is very easy to use in launching a simple backand with FastAPI. That's why I'm saving the code.

How to run:

  1. cd into the api folder
  2. run the ./package_for_lambda.sh command this packages all the requirements up in a .zip file for Lambda
  3. cd into the crud-infra folder and run: cdk deploy

You may need to use NPM install to install packages or run cdk bootstrap in order to get the environment set up. The installation also assumes you already are logged into the AWS CLI. In case you cannot redeploy check for S3 buckets with config files stored.

Endpoint

API Folder

The /api folder contains the Python FastAPI code. Run this shell script to build the code into a zip (required for CDK to upload to Lambda):

# Only work on UNIX (Mac/Linux) systems!
./package_for_lambda.sh

This should generate a lambda_function.zip.

Infrastructure Folder

The /crud-infra folder contains the CDK code to deploy all the infrastructure (Lambda function and DynamoDB table) to your AWS account.

You must have AWS CLI configured, and AWS CDK installed on your machine.

First, install the node modules.

npm install

Then run bootstrap if you never used CDK with your account before.

cdk bootstrap

Now you can use this to deploy.

cdk deploy

Test Folder

This contains the Pytest integration tests you can use to test your endpoint directly. Don't forget to change your ENDPOINT to the one you want to use (in api_integration_test.py).

You can run the test like this (but you have to have pytest installed):

pytest

About


Languages

Language:Python 61.2%Language:TypeScript 24.3%Language:JavaScript 12.3%Language:Shell 2.2%