AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::SNS::Subscription

The AWS::SNS::Subscription resource subscribes an endpoint to an Amazon Simple Notification Service (Amazon SNS) topic. The owner of the endpoint must confirm the subscription before Amazon SNS creates the subscription.

Syntax

JSON

{ "Type" : "AWS::SNS::Subscription", "Properties" : { "DeliveryPolicy" : JSON object, "Endpoint" : String, "FilterPolicy" : JSON object, "Protocol" : String, "RawMessageDelivery" : Boolean, "Region" : String, "TopicArn" : String } }

YAML

Type: "AWS::SNS::Subscription" Properties: DeliveryPolicy: JSON object Endpoint: String FilterPolicy: JSON object Protocol: String RawMessageDelivery: Boolean, Region: String TopicArn: String

Properties

DeliveryPolicy

The JSON serialization of the subscription's delivery policy. For more information, see GetSubscriptionAttributes in the Amazon Simple Notification Service API Reference.

Required: No

Type: JSON object

Update requires: No interruption

Endpoint

The endpoint that receives notifications from the Amazon SNS topic. The endpoint value depends on the protocol that you specify. For more information, see the Subscribe Endpoint parameter in the Amazon Simple Notification Service API Reference.

Required: No

Type: String

Update requires: Replacement

FilterPolicy

The filter policy JSON that is assigned to the subscription. For more information, see GetSubscriptionAttributes in the Amazon Simple Notification Service API Reference.

Required: No

Type: JSON object

Update requires: No interruption

Protocol

The subscription's protocol. For more information, see the Subscribe Protocol parameter in the Amazon Simple Notification Service API Reference.

Required: Yes

Type: String

Update requires: Replacement

RawMessageDelivery

true if raw message delivery is enabled for the subscription. Raw messages are free of JSON formatting and can be sent to HTTP/S and Amazon SQS endpoints. For more information, see GetSubscriptionAttributes in the Amazon Simple Notification Service API Reference.

Required: No

Type: Boolean

Update requires: No interruption

Region

The region in which the topic resides.

Required: No

Type: String

Update requires: Replacement

TopicArn

The Amazon Resource Name (ARN) of the topic to subscribe to.

Required: Yes

Type: String

Update requires: Replacement

Example

Create a subscription with mandatory attributes

The following example creates a subscription with Endpoint, Protocol and TopicArn only.

JSON

"MySubscription" : { "Type" : "AWS::SNS::Subscription", "Properties" : { "Endpoint" : "test@email.com", "Protocol" : "email", "TopicArn" : {"Ref" : "MySNSTopic"} } }

YAML

MySubscription: Type: AWS::SNS::Subscription Properties: Endpoint: test@email.com Protocol: email TopicArn: !Ref 'MySNSTopic'

Create a subscription with optional attributes

The following example creates a subscription with FilterPolicy, DeliveryPolicy and RawMessageDelivery.

Note that SNS subscription attributes can be set on standalone SNS subscriptions only, as opposed to SNS subscriptions nested in SNS topics.

JSON

{ "AWSTemplateFormatVersion": "2010-09-09", "Resources": { "CarSalesTopic": { "Type": "AWS::SNS::Topic" }, "ERPSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Fn::GetAtt": ["ERPIntegrationQueue", "Arn"] }, "Protocol": "sqs", "RawMessageDelivery": "true" } }, "CRMSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Fn::GetAtt": ["CRMIntegrationQueue", "Arn"] }, "Protocol": "sqs", "RawMessageDelivery": "true", "FilterPolicy": { "buyer-class": [ "vip" ] } } }, "SCMSubscription": { "Type": "AWS::SNS::Subscription", "Properties": { "TopicArn": { "Ref": "CarSalesTopic" }, "Endpoint": { "Ref": "myHttpEndpoint" }, "Protocol": "https", "DeliveryPolicy": { "healthyRetryPolicy": { "numRetries": 20, "minDelayTarget": 10, "maxDelayTarget": 30, "numMinDelayRetries": 3, "numMaxDelayRetries": 17, "numNoDelayRetries": 0, "backoffFunction": "exponential" } } } }, "ERPIntegrationQueue": { "Type": "AWS::SQS::Queue", "Properties": {} }, "CRMIntegrationQueue": { "Type": "AWS::SQS::Queue", "Properties": {} } }, "Parameters": { "myHttpEndpoint": { "Type": "String" } } }

YAML

AWSTemplateFormatVersion: 2010-09-09 Resources: CarSalesTopic: Type: 'AWS::SNS::Topic' ERPSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !GetAtt - ERPIntegrationQueue - Arn Protocol: sqs RawMessageDelivery: 'true' CRMSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !GetAtt - CRMIntegrationQueue - Arn Protocol: sqs RawMessageDelivery: 'true' FilterPolicy: buyer-class: - vip SCMSubscription: Type: 'AWS::SNS::Subscription' Properties: TopicArn: !Ref CarSalesTopic Endpoint: !Ref myHttpEndpoint Protocol: https DeliveryPolicy: healthyRetryPolicy: numRetries: 20 minDelayTarget: 10 maxDelayTarget: 30 numMinDelayRetries: 3 numMaxDelayRetries: 17 numNoDelayRetries: 0 backoffFunction: exponential ERPIntegrationQueue: Type: 'AWS::SQS::Queue' Properties: {} CRMIntegrationQueue: Type: 'AWS::SQS::Queue' Properties: {} Parameters: myHttpEndpoint: Type: String

On this page: