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.
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.7.
- Create a new role with basic Lambda permissions. You will have to update this manually using the IAM policy here.
- Click Create function.
- Select SQS as the trigger, and choose the queue named Messages.
- Click Add.
- Click the function name at the top of the page to enable the function editor.
- Paste in the function body using the source code here.
- Set an environment variable called
DYNAMODB_TABLE, and set its value to "Message".
- Save the Lambda function.
- Send Messages to SQS
Note: Full source code is available here.
- Connect to the public EC2 instance using the provided credentials.
- Install the prerequisites for Python, as well as Python, Boto3, and the Faker library.
send_message.pyscript to send a message containing random text to the
Messagesqueue every 0.1 seconds (10 messages per second):
./send_message.py -q Messages -i 0.1
- Press Ctrl+C to quit.
- Verify a record has been written to DynamoDB.
- Using CloudWatch Logs, verify the Lambda function has been triggered.