Triggering Lambda from Amazon SQS

45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

In this hands-on AWS lab, you will learn how to trigger a Lambda function using SQS. This Lambda function will process messages from the SQS queue and insert the message data as records into a DynamoDB table.

– Download the Lambda execution role IAM policy [here ( ).
– Download the Lambda function source code [here] ( ).

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the Lambda Function
  1. In the AWS Management Console, navigate to Lambda.
  2. Select Create a function.
  3. Give the function any name you like (e.g., "SQSDynamoDB").
  4. Under Runtime, choose Python 3.7.
  5. Create a new role with basic Lambda permissions. You will have to update this manually using the IAM policy here.
  6. Click Create function.
  7. Select SQS as the trigger, and choose the queue named Messages.
  8. Click Add.
  9. Click the function name at the top of the page to enable the function editor.
  10. Paste in the function body using the source code here.
  11. Set an environment variable called QUEUE_NAME and set its value to Messages (the name of the SQS queue).
  12. Set an environment variable called MAX_QUEUE_MESSAGES and set its value to 10 (the maximum message batch size to receive from SQS).
  13. Set an environment variable called DYNAMODB_TABLE and set its value to Message.
  14. Save the Lambda function.
Send Messages to SQS
  1. Connect to the public EC2 instance using the provided credentials.
  2. Run the script to send messages to SQS:
    • Example: To send a message containing random text to the Messages queue every 0.1 seconds (10 messages per second):
      ./ -q Messages -i 0.1
      Type Ctrl + C to quit.
      Full source code is available here.
  3. Using CloudWatch Logs, verify that the Lambda function has been triggered.
  4. Verify that a record has been written to DynamoDB.

Additional Resources

Make sure you are in the us-east-1 region.

An SQS topic and DynamoDB table have been provided for you. The EC2 instance contains a script called that you can use to quickly send a high volume of messages to SQS.

  • Download the Lambda execution role IAM policy here.
  • Download the Lambda function source code here.

Configure the Lambda function so that it is triggered by the SQS queue. Make sure that each message sent to the SQS queue is inserted into DynamoDB.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?