DEV Community

Cover image for How to Invoke AWS Lambda Functions from Amazon SQS Message
Albine Peter
Albine Peter

Posted on

How to Invoke AWS Lambda Functions from Amazon SQS Message

Image description

To invoke AWS Lambda functions from an Amazon SQS (Simple Queue Service) message, you need to create an event source mapping that connects the SQS queue to the Lambda function.

I have used this code :
import json

def lambda_handler(event, context):
for record in event['Records']:
# SQS message body
body = record['body']
print(f"Message Body: {body}")
# Process the message here
# ...
return {
'statusCode': 200,
'body': json.dumps('Success')
}

  1. Create an SQS Queue
  2. Create an AWS Lambda Function
  3. Set Up Event Source Mapping
  4. Grant Permissions

Summary:
By following these steps, your Lambda function will be invoked whenever a new message is sent to your SQS queue. The Lambda function will process the messages as they arrive, allowing you to handle them asynchronously.

If you have specific requirements or configurations, feel free to share, and I can provide more detailed guidance.

Top comments (0)