Python – Are AWS SNS records always a single element list?

Are AWS SNS records always a single element list?… here is a solution to the problem.

Are AWS SNS records always a single element list?

AWS SNS events have a list of records that contain messages for a given notification. Is it always a single list of elements?

The

blueprint code to read SNS messages in Node is…

const message = event. Records[0]. Sns.Message;

In Python it is…

message = event['Records'][0]['Sns']['Message']

Solution

Each AWS SNS notification will contain no more than 1 message.

Read the reliability section in the SNS FAQ: https://aws.amazon.com/sns/faqs/

That being said, there will be only one record per Lambda function trigger

Now you may encounter why the event. Is the problem with Records being defined as an array? Can it be triggered by multiple entries in other ways?

The answer is that Records is an array because other event sources can send multiple events at once (such as s3 events or dynamo database streams), but for SNS, although it is an array, there is only one sns message.

Related Problems and Solutions