63

When receiving events in Lambda from SNS the outer structure of the event will look somewhat like:

{ "Records": [...] }

In all the tutorials I have seen there has only ever been 1 record in the records field.

Is it safe to make the assumption that the "Records"-array will only ever contain 1 item?

Philipp Kyeck
  • 18,402
  • 15
  • 86
  • 123
RckMrkr
  • 985
  • 1
  • 10
  • 14

2 Answers2

74

Each SNS notification will contain not more than one message.

Refer Reliability section in SNS FAQ : https://aws.amazon.com/sns/faqs/

Having said that, each lambda function trigger will have just a single record

omuthu
  • 5,948
  • 1
  • 27
  • 37
  • 8
    i know its been a while, but any idea why the event.Records is defined as an array then? can it be triggered by another means with multiple entries? – Dave Mar 12 '18 at 16:06
  • 19
    Records is an array because other event sources can send multiple events at one shot (like dynamodb streams or s3 events) but for SNS though it is an array will have just one sns message – omuthu Mar 12 '18 at 19:22
  • If you push SNS notifications to SQS and the Lambda function subscribes to it, the function can retrieve up to 10 messages at a time for processing. – Riku L Dec 19 '18 at 11:05
  • @omuthu I have a sns topic to which various resources such as aws step functions ,ses publish. a lambda is subscribed to this sns topic whose responsibility is to identify where this record generated and classify as critical or non critical .records coming from sns always have eventsource as aws:sns but not where it originated , but i want my lambda to know from where sns got the notification. is there any way to achieve this? – Sithija Piyuman Thewa Hettige Jun 28 '20 at 05:02
  • @SithijaPiyumanThewaHettige No way you can achieve that until you read the message and find it. Better way would be is to have separate SNS for each category and then have same lambda to be triggered by both SNS. – omuthu Jun 28 '20 at 13:47
10

Just ran into the same thing, and for posterity, I think it is worth adding that in the official AWS tutorial, they rely on there being exactly one record:

https://docs.aws.amazon.com/lambda/latest/dg/with-sns-create-package.html

James Flight
  • 1,424
  • 1
  • 13
  • 21