Want to be able to test your code by leveraging AWS resources locally? Confirm the impact of configurations and IaC you've expressed with Terraform?
Localstack aggregates various service providers that implement emulations of the AWS APIs. It also supports various IaC integrations to spin up requested infrastructure in an automated fashion.
This demo provides a skeleton of various AWS resources in Terraform to test or build off of, and a docker-compose with Localstack and dynamodb-admin for easy DB management.
The base Terraform script without any modification will stand up an SQS queue, a Lambda which has an event source mapping from the queue, and a DynamoDB table.
The demo flow goes as follows:
- Write a message to our input SQS queue
- Localstack's event source mapping handler will acknowledge receipt of the message and spin up a separate container to emulate the Lambda
- The Lambda will wrap the incoming message body with a corresponding ID and timestamp and then persist this record to our output DynamoDB table
- Install Terraform to actually execute the pre-provided Terraform script or your own
- Install terraform-local with pip to get a Terraform wrapper macro,
tflocal
, which points your Terraform commands to our Localstack - Install awscli-local with pip to get an AWS CLI wrapper macro,
awslocal
, which points your AWS CLI commands to our Localstack - (If wanting to make changes) Modify this repo's main.tf Terraform script to add your intended AWS resources
- Stand up the containers with:
docker-compose up
- Apply your Terraform infrastructure to the Localstack container with:
tflocal init
tflocal apply
- Once changes are applied, you can use
awslocal
replacing anyawscli
command to test your infrastructure!
At this point, if you wish to test our demo flow functionality:
- Submit a message to the input queue with:
awslocal sqs send-message --queue-url http://localhost:4566/000000000000/input_queue --message-body "Any message can go here!"
- Confirm in your Docker Desktop that a lambda container has been spun up and/or that the Localstack container has acknowledged receiving the message
- Confirm via dynamodb-admin that the event was persisted to our output table by accessing the UI at: http://localhost:8001
Try forking this repo and add more AWS resources using the Terraform docs as a guide!
Be mindful though, Localstack doesn't guarantee full AWS API coverage for all resources, so check their feature coverage table to confirm that they support any resources that you're adding.