AWS CloudFormation
User Guide (Version )

AWS::SNS::Subscription

The AWS::SNS::Subscription resource subscribes an endpoint to an Amazon Simple Notification Service (Amazon SNS) topic. For a subscription to be created, the owner of the endpoint must confirm the subscription.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

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

YAML

Type: AWS::SNS::Subscription Properties: DeliveryPolicy: Json Endpoint: String FilterPolicy: Json 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

Update requires: No interruption

Endpoint

The subscription's endpoint. The endpoint value depends on the protocol that you specify. For more information, see the Endpoint parameter of the Subscribe action in the Amazon Simple Notification Service API Reference.

Required: No

Type: String

Update requires: Replacement

FilterPolicy

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

Required: No

Type: Json

Update requires: No interruption

Protocol

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

Required: Yes

Type: String

Update requires: Replacement

RawMessageDelivery

When set to true, enables raw message delivery. Raw messages don't contain any JSON formatting and can be sent to Amazon SQS and HTTP/S endpoints. For more information, see GetSubscriptionAttributes in the Amazon Simple Notification Service API Reference.

Required: No

Type: Boolean

Update requires: No interruption

Region

For cross-region subscriptions, the region in which the topic resides.

Required: No

Type: String

Update requires: Replacement

TopicArn

The ARN of the topic to subscribe to.

Required: Yes

Type: String

Update requires: Replacement

Examples

Create a subscription with mandatory attributes

The following example creates a subscription with only an endpoint, protocol, and topic ARN.

JSON

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

YAML

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

Create a subscription with optional attributes

The following example creates a subscription with a filter policy, delivery policy, and raw message delivery enabled.

Note

You can set subscription attributes only on standalone Amazon SNS subscriptions (not on subscriptions nested in topics).

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

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" } } }

On this page: