Menu
Amazon Simple Notification Service
Developer Guide (API Version 2010-03-31)

Invoking Lambda functions using Amazon SNS notifications

Amazon SNS and AWS Lambda are integrated so you can invoke Lambda functions with Amazon SNS notifications. When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda function is invoked with the payload of the published message. The Lambda function receives the message payload as an input parameter and can manipulate the information in the message, publish the message to other SNS topics, or send the message to other AWS services.

In addition, Amazon SNS also supports message delivery status attributes for message notifications sent to Lambda endpoints. For more information, see Using Amazon SNS Topic Attributes for Message Delivery Status.

Prerequisites

To invoke Lambda functions using Amazon SNS notifications, you need the following:

  • Lambda function

  • Amazon SNS topic

For information on creating a Lambda function, see Getting Started with AWS Lambda. For information on creating a Amazon SNS topic, see Create a Topic.

Configuring Amazon SNS with Lambda Endpoints with the AWS Management Console

  1. Sign in to the AWS Management Console and open the Amazon SNS console at https://console.aws.amazon.com/sns/.

  2. In the left Navigation pane, click Topics, and then click the topic to which you want to subscribe a Lambda endpoint.

  3. Click Actions and then click Subscribe to topic.

  4. In the Protocol drop-down box, select AWS Lambda.

  5. In the Endpoint drop-down box, select the ARN for the Lambda function.

  6. In the Version or Alias drop-down box, select an available version or alias to use. You can also choose $LATEST to specifiy the latest version of the Lambda function. If you do not want to specify a version or alias, you can also choose default, which is functionally the same as $LATEST. For more information, see AWS Lambda Function Versioning and Aliases.

  7. Click Create subscription.

When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda function is invoked with the payload of the published message. For information on how to create a sample message history store using SNS, Lambda, and Amazon DynamoDB, see the AWS Mobile Development blog Invoking AWS Lambda functions via Amazon SNS.