- A Cloud Guru
Triggering AWS Lambda from Amazon SQS
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.
Table of Contents
Create the Lambda Function
- Navigate to Lambda.
- Select Create a function.
- Give the function the name SQSDynamoDB.
- Under Runtime, choose Python 3.8.
- Select the Use an existing role and select lambda-execution-role.
- Click Create function.
Create the SQS Trigger
- Click Add trigger.
- Search for SQS and select it.
- Under SQS queue, select Messages.
- Leave the rest as default, and ensure Enable trigger is selected.
- Click Add.
Copy the Source Code into the Lambda Function
- Open the lambda function code by double-clicking lambda_function.py.
- Paste in the source code from here.
- Deploy the Lambda function.
Log In to the EC2 Instance and Test the Script
- Connect to the EC2 instance as shown.
su - cloud_user.
./send_message.py -q Messages -i 0.1.
Confirm Messages Were Inserted into the DynamoDB Table
- Open the DynamoDB console.
- Open the Message table.
- Open the Items tab.
- Confirm Items is populated.
What's a lab?
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.