2
votes

I am facing the problem of how to trigger a Lambda function after a message has been written in a SQS queue which is a SNS subscriber.

I know there is this useful post but I have not really understood how to publish a second message (on topic B) after the first one has been successfully sent (on topic A). I did not know if it is the right answer.

Here below there is a diagram of what I would link to implement

enter image description here

As you can see there is an API which publish to an SNS topic. The subscribers of this topic should be:

  1. An SQS queue where a message is stored
  2. A Lambda function which has to been triggered by SNS to consume the message written to the queue.

The problem I am facing is how to be sure the lambda is executed after a message has been written in the queue and how to really implement the solution. How to publish two topic and from one writing message in SQS and from the other one trigger the queue (how can be sure the message has been effectively written in the queue?).

Thank you very much guys, hope I was clear enough.

1
could anyone help me? - Paride Letizia
What are the reasons for this architecture? I.e. what happens with the message after it's send to the queue? Would it be an alternative for you that your Lambda function publishes the event to SQS? In that case you'd know when the event has been sent to SQS. - s.hesse
The problem is that SQS isn't able to trigger Lambda function so I would like that SNS sequentially writes on SQS first and then trigger Lambda function - Paride Letizia
Ok. You might read this tutorial which proposes a solution to read new SQS entries with a Lambda function. - s.hesse

1 Answers

0
votes

Add the lambda to the topic as a subscriber. As soon as a message is published to the topic,lambda will be triggered. If you have an SQS queue as a subscriber to the topic, then the message will be queued there too..