Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke AWS Lambda SNS event only after SQS subscription on same topic has been processed

I would like to implement an Amazon SNS topic which first delivers messages to a SQS queue that is a subscriber on the topic, and then executes an AWS Lambda function that is also a subscriber on the same topic. The Lambda function can then read messages from the SQS queue and process several of them in parallel (hundreds).

My question is whether there is any way to guarantee that messages sent to the SNS topic would first be delivered to the SQS queue, and only then to the Lambda function?

The purpose of this is to scale to a large number of messages without having to execute the Lambda function separately for every single message.

like image 281
Kennu Avatar asked May 26 '15 13:05

Kennu


People also ask

Can SQS subscribe to SNS in different account?

Sending Amazon SNS messages to an Amazon SQS queue in a different account. You can publish a notification to an Amazon SNS topic with one or more subscriptions to Amazon SQS queues in another account.

How does SNS and SQS work together?

When you subscribe an Amazon SQS queue to an Amazon SNS topic, you can publish a message to the topic and Amazon SNS sends an Amazon SQS message to the subscribed queue. The Amazon SQS message contains the subject and message that were published to the topic along with metadata about the message in a JSON document.

Can a Lambda be triggered by multiple SQS?

A Lambda function can process items from multiple queues (using one Lambda event source for each queue). You can use the same queue with multiple Lambda functions.


1 Answers

For this purpose, triggering the lambda could be better and efficient if used from a cloud watch alert. With the cloud watch alert set at a buffer limit on the SQS, that could fire the lambda to start and process the full queue.

like image 73
Jiju Thomas Mathew Avatar answered Sep 27 '22 19:09

Jiju Thomas Mathew