An example to use Terraform to create an AWS Lambda function with an API gateway.
- Create a
requirements.txt
file from pipenv
pipenv requirements > requirements.txt
- Install the requests library to a new package directory.
pip install --target ./infrastructure/package -r requirements.txt
- Create a deployment package with the installed library at the root.
cd infrastructure/package
zip -r ../my-deployment-package.zip .
- Add the
main.py
file to the root of the zip file.
cd ..
zip my-deployment-package.zip ../main.py
- Export your AWS Environment variables.
export AWS_ACCESS_KEY_ID=put_your_key_here
export AWS_SECRET_ACCESS_KEY=put_your_secret_here
- Initialize Terraform
Make sure you're inside the infrastructure folder.
terraform init
- Populate the AccountId Variable
In the file terraform.tfvars
, put in your account ID. You can find it by clicking in the top right corner of the AWS console.
- Plan Terraform
terraform plan
- Apply Terraform
terraform apply
- Go to the URL output of Terraform
The default query has ?amount=100&fromCurrency=USD&toCurrency=CAD
Change the amount and from and to currency to see different conversions.
- Clean up
terraform destroy