Amazon SNS
Trigger AWS Lambda from SNS
In this pattern, we will walk through how to trigger AWS Lambda from messages sent to an SNS topic.
Packages Required
Function Code
The S3 to Lambda integration is what is known as an asynchronous invoke. Events are forwarded to the Lambda service and processed asynchronously, meaning the caller can continue doing other work.
The SNSEvent
object contains a List of SNSRecord
objects. The SNSRecord
objects contains all the message metadata including the Message body itself, the type of message and the ARN of the topic the message came from.
It's important to implement error handling and dead letter queues. If the Lambda functions fails and no dead letter queue is configured, messages will be lost.
Best Practices
- Ensure errors are handled. If the Lambda function fails messages will be lost if no dead letter queue is configured