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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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.
- Run
su - cloud_user
. - Run
./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.