Skip to content

satendrakumar/fastapi-on-aws-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastapi-on-aws-lambda

Deploying a FastAPI app on AWS Lambda using AWS SAM

Deploy the sample application

  sam build --use-container
  sam deploy --guided
  #You can find your API Gateway Endpoint URL in the output values displayed after deployment.
  # next time 
  sam build && sam deploy --no-confirm-changeset

Use the SAM CLI to build and test locally

Build your application with the `sam build --use-container` command.
  sam build --use-container

Run on local:

  sam local start-api
  curl http://localhost:3000/
  # API  test 
  curl -XPOST -H 'Content-Type: application/json' -d '{"id":1, "name":"test"}' 'http://localhost:3000/items/create'
  # response {"item_id":1,"name":"test"}
   curl 'http://localhost:3000/items/42?q=test'
  #Response: {"item_id":42,"q":"test"

Logs:

  sam logs -n FastAPIFunction --stack-name "fastapi-on-aws-lambda" --tail

Tests

Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
    pip install -r tests/requirements.txt --user
    # unit test
    python -m pytest tests/unit -v
    # integration test, requiring deploying the stack first.
    # Create the env variable AWS_SAM_STACK_NAME with the name of the stack we are testing
    AWS_SAM_STACK_NAME="fastapi-on-aws-lambda" python -m pytest tests/integration -v

Cleanup

To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
sam delete --stack-name "fastapi-on-aws-lambda"

About

Deploying a FastAPI app on AWS Lambda using AWS SAM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages