1
votes

I'm in a situation where I need to process some notifications from a SNS topic. I'm thinking about processing this message in a Lambda function. I have to implementation in mind

  1. Subscribe Lambda function to the topic and process the notification
  2. Subscribe a SQS queue (Fifo) to the topic and then Lambda function will be invoked based on the notifications in the queue.

Order of the message is import for the consumer application. Keeping this in mind which one seems to be a better implementation. Any pointers/explanation would be helpful.

2
How strict is the ordering requirement? What is the message velocity (i.e. 1 message a minute or 100,000 messages a second)? Lambda may not be your best bet as it can't scale very well if the message ordering is absolute.stdunbar
The frequency of the operation is pretty low - a few hundred notifications in an hour. Messages are related to life cycle of aws resources including applications - say created, deployed, deleted. So order is important for us.kallada

2 Answers

2
votes

It sounds more like multiple somewhat independent message streams. So if a created event for EC2-1 came in before one for EC2-2 there really isn't an issue. In that case I would stick with the SNS -> Lambda method as the SQS method will require polling of the queue. The Lambda won't cost anything if it's not being used but you will (eventually) get charged for SQS polling.

There are many examples of how to handle the messages coming in. In Java, for example, you can use POJO handlers (a plain old java object for which Lambda has done the deserialization for you or you could used predefined objects that, in this case, are SNS specific.

1
votes

You can subscribe your SQS FIFO queues to an SNS FIFO topic. Then, you can have your queues trigger the Lambda functions, in order. Here’s an example: https://docs.aws.amazon.com/sns/latest/dg/fifo-example-use-case.html