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

Using Amazon SNS for System-to-System Messaging with a Lambda Function as a Subscriber

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 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/v2/home.

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

  3. Choose Actions and then choose 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. If you don't want to specify a version or alias, you can choose default (the latest version).

    Note

    Lambda doesn't allow event sources to be added for $LATEST. However, it allows event sources on unqualified ARNs (effectively $LATEST).

    For more information, see AWS Lambda Function Versioning and Aliases.

  7. Choose 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.