AWS Compute Blog

Using Amazon SNS to Trigger Lambda Functions

Tim Wagner Tim Wagner, AWS Lambda

Using Amazon SNS to Trigger Lambda Functions

Sending messages to SNS can now also trigger Lambda functions, allowing you to add arbitrary compute capabilities to any service or application that knows how to send messages, such as Amazon CloudWatch alarms.

Intelligent IT: Triggering Code by Sending it Messages

SNS is an easy and scalable way to send notifications and already supports a variety of targets, including SQS, email, and both HTTP and mobile endpoints. SNS now can also trigger a Lambda function in response to a message, allowing you to turn existing messaging frameworks, such as CloudWatch alarms, into workflows that can execute arbitrary code and call any AWS API.

Intelligent Messaging

Now that SNS can call Lambda (and as always, Lambda can call SNS), you can do some amazing things by combining the reach of SNS messages with the ability to easy run arbitrary code in Lambda:

  • Targeting. You can generate messages using templates stored in Amazon DynamoDB or Amazon S3 and compute or fill in values on the fly.
  • Routing and filtering. Turn one message into many or filter many down to one.
  • Logging and auditing. Easily retain a full or partial copy of messages. Watch for and elide sensitive information or stamp a watermark into each message as it flows by.

The AWS Mobile blog has a great step-by-step example that demonstrates how you can create a message log in Amazon DynamoDB using a simple AWS Lambda function to record each message.

Can’t wait to see what other creative ideas developers have for using Lambda and SNS together!