Based on https://adem.sh/blog/tutorial-fastapi-aws-lambda-serverless
- Node installation (tested with
v18.7.0) - Python
- Docker (required for packaging dependencies)
- You can alternatively set
dockerizePiptofalse
- You can alternatively set
- Create and activate your Python virtual environment (Python 3.9 recommended)
python -m venv .venvsource .venv/bin/activate
pip install -r requirements.txt- Run locally with
uvicorn main:app --reload - Auto-generated docs at: http://127.0.0.1:8000/docs
- Run
npm installfrom the root of this repository - Set up AWS credentials (AWS profile or other means)
- Create a
.envfile from.env.examplefor your local environment - Create an additional env file each environment you intend to deploy (e.g.
.env.staging) - Specify the desired domain for your API as the value of the
BASE_URLenv variable e.g.api.example.com- Create your certificate with Certificate Manager in the us-east-1 region
- Copy the ARN of the certificate and use it as the value for
CERTIFICATE_ARNin.env
- Ensure that Docker is running (or set
dockerizePiptofalse) - Deploy with
NODE_ENV=staging sls deploy --stage staging, wherestagingcan be substituted for any environment name. - To deploy with specific AWS profile, use the
--aws-profileflag, e.g.NODE_ENV=staging sls deploy --stage staging --aws-profile default
With credentials configured, run:
sls remove --stage staging- Manually remove the certificate you created for your domain