DoArNa
DoArNa

Reputation: 532

Sending multiple messages to SNS on a single call

I have a scenario where every time lambda runs, it will send 1000 messages to a SNS topic. I can loop through the list of messages and call the publish method 1000 times, one message at a time but I was wondering if there is a way to send multiple messages in one call. In that case I can batch the messages and call publish let say 10 with 100 messages on each execution.

I would really appreciate if someone can help on this.

Upvotes: 4

Views: 5132

Answers (3)

Otavio Ferreira
Otavio Ferreira

Reputation: 966

SNS has just introduced the PublishBatch API, which you can use to send up to 10 messages to an SNS topic in a single API request. More information on the feature launch can be found here: https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-sns-supports-publishing-batches-messages-single-api-request/

Upvotes: 4

CK__
CK__

Reputation: 1311

With SNS publish you could publish message one by one, AWS does not provide a way to publish message in bulk or batch to SNS.

Below is the possible solution you could try:

You could use send-message-batch API and send bulk messages to SQS. That SQS will be subscribed by a SNS. Below is an image to create subscription to SQS:

enter image description here

Upvotes: 2

Prashanna
Prashanna

Reputation: 1001

You can't achieve it directly via SNS maybe you can have a SQS queue at the front and back of SNS to post and receive messages as batch.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessageBatch.html

Upvotes: 2

Related Questions