Amazon SQS to AWS Lambda

SQS → AWS Lambda

Create a Lambda function that subscribes to an SQS queue

This pattern deploys deploys a Lambda function and an SQS queue. SQS invokes the Lambda function when new messages are available. The CDK application contains the minimum IAM resources required to run the application.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/sqs-lambda-cdk-python

Deploy

cdk deploy


Testing

Use the AWS CLI to send a message to the SQS queue and observe the event delivered to the Lambda function:
1. Delete the stack: sam delete --stack-name STACK_NAME.
1. Send the SQS message: aws sqs send-message --queue-url ENTER_YOUR_SQS_QUEUE_URL --message-body "Test message"
2. Retrieve the logs from the Lambda function: aws logs describe-log-streams --log-group-name '/aws/lambda/ENTER_YOUR_FUNCTION_NAME' --query logStreams[*].logStreamName.

Cleanup

1. Delete the stack: cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Created by:

Corneliu Croitoru

Corneliu Croitoru

Developer at heart, in 2018 joined AWS as a Solution Architect and since 2021 building, jointly with customers, the most exciting and innovative prototypes on AWS.

Follow on LinkedIn