Skip to content

An example to use Terraform to create an AWS Lambda function with an API gateway.

License

Notifications You must be signed in to change notification settings

samgabrail/aws-lambda-terraform

Repository files navigation

Overview

An example to use Terraform to create an AWS Lambda function with an API gateway.

Instructions

  1. Create a requirements.txt file from pipenv
pipenv requirements > requirements.txt
  1. Install the requests library to a new package directory.
pip install --target ./infrastructure/package -r requirements.txt
  1. Create a deployment package with the installed library at the root.
cd infrastructure/package
zip -r ../my-deployment-package.zip .
  1. Add the main.py file to the root of the zip file.
cd ..
zip my-deployment-package.zip ../main.py
  1. Export your AWS Environment variables.
export AWS_ACCESS_KEY_ID=put_your_key_here
export AWS_SECRET_ACCESS_KEY=put_your_secret_here
  1. Initialize Terraform

Make sure you're inside the infrastructure folder.

terraform init
  1. 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.

  1. Plan Terraform
terraform plan
  1. Apply Terraform
terraform apply
  1. 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.

  1. Clean up
terraform destroy

About

An example to use Terraform to create an AWS Lambda function with an API gateway.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published