Use Terraform and LocalStack to configure a Lambda function and function URL. LocalStack acts as a stand-in for AWS, there's no need an AWS account or access keys. The initial configuration in main.tf configures Terraform to make calls to the LocalStack container.
All can be installed via Homebrew on macOS or Linux
- Python:
brew install python@3.11 - Docker CLI:
brew install docker - Colima:
brew install colima(likely only needed on macOS) - Localstack:
brew install localstack - Terraform:
brew install terraform
Note that the LocalStack Python package must be installed on your host machine – running only the LocalStack Docker container is not sufficient to complete this exercise.
-
Make sure Docker (or Colima) is running
-
Start LocalStack:
$ localstack start
-
Clone this repo to a local working directory
-
Initialize a Terraform root module within the repo directory
- Write Terraform configuration for a Lambda function that runs the Python code contained in the
lambda/directory - Validate, plan, and apply your changes
- Write Terraform configuration for a Lambda function URL for the function you created
- Validate, plan, and apply your changes
- Get the URL of the Lambda function you created
- Call the Lambda function using
curland observe its output - Destroy the running infrastructure