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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more