Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconapi-gateway-account-settings
file-type-iconlambda-build
file-type-iconlambda-dead-letter-queue
file-type-iconpython
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconlambda-edge
file-type-iconlambda-keep-warm
file-type-iconlambda-s3-deployment-package
file-type-iconlambda-s3
file-type-iconlambda-service
file-type-iconlambda-vpc
file-type-iconscheduled-lambda-job
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconowners.txt
file-type-iconterraform-cloud-enterprise-private-module-...

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconexamples
file-type-iconapi-gateway-account-settings
file-type-iconlambda-build
file-type-iconlambda-dead-letter-queue
file-type-iconpython
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvars.tf
file-type-iconlambda-edge
file-type-iconlambda-keep-warm
file-type-iconlambda-s3-deployment-package
file-type-iconlambda-s3
file-type-iconlambda-service
file-type-iconlambda-vpc
file-type-iconscheduled-lambda-job
file-type-iconmodules
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconowners.txt
file-type-iconterraform-cloud-enterprise-private-module-...
AWS Lambda

AWS Lambda

Deploy Lambda functions with Terraform. Supports uploading deployment packages, configuring environment variables, and scheduled functions.

Code Preview

Preview the Code

mobile file icon

README.md

down

Lambda Dead Letter Queue

This folder shows an example of how to configure the dead letter queue config within the lambda or lambda-edge module.

How do you run this example?

To apply the Terraform templates:

  1. Install Terraform.
  2. Open vars.tf, set the environment variables specified at the top of the file, and fill in any other variables that don't have a default.
  3. Run terraform get.
  4. Run terraform plan.
  5. If the plan looks good, run terraform apply.

How do you test the Lambda function?

Testing the lambda function and dead letter config once it is deployed must be done using the AWS CLI

Test with AWS CLI

After installing the AWS CLI, run the following command:

echo '{ "test-name": "my-test", "message": "hello world" }' | base64 > payload.b64
aws lambda invoke --function-name lambda-dead-letter-queue  --invocation-type Event --payload file://payload.b64 response.json

Replace lambda-dead-letter-queue with the name of the function if needed (the name of the function is provided as an output after running terraform apply). The parameter --invocation-type Event must be included for async invocation.

Note that the lambda is expected to throw an expection, which will then trigger the dead letter queue. After invoking the lambda, a new message should be waiting in the SQS queue (see the outputs from terraform apply for the name of the configured queue).

Checkout Asynchronous Invocation for more information on invoking lambdas asynchronously, including via API Gateways.

To verify message have been sent to the queue, go to the SQS Console, locate the queue, then click on the Monitoring tab to view a line graph of inbound messages received.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?