AWS Lambda to Amazon SQS

AWS Lambda → SQS

Create a Lambda function that publishes to an SQS queue

This Serverless Framework project deploys a Lambda function, an SQS queue and the IAM permissions required to run the application. The Lambda function publishes a message to the SQS queue when invoked.

< 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/lambda-sqs-sls

Deploy

serverless deploy


Testing

Use the AWS CLI to invoke the Lambda function. The function name is in the outputs of the AWS SAM deployment (the key is QueuePublisherFunction):
1. Invoke the Lambda function to publish a message to the SQS queue: aws lambda invoke --function-name ENTER_YOUR_FUNCTION_NAME outfile.txt.
2. Retrieve the message from the SQS queue, using the queue URL from the AWS SAM deployment outputs: aws sqs receive-message --queue-url ENTER_YOUR_QUEUE_URL

Cleanup

1. Delete the stack: serverless remove.
2. Confirm the stack has been deleted: serverless info

Created by:

Alex Nelson

Senior Solutions Architect, AWS