Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a SNS subscription with CloudFormation without creating a topic?

Is it possible to create a 'Subscription' resource in a AWS CloudFormation JSON template without creating a new AWS::SNS::Topic?

In my case, the topic is created outside of the CloudFormation script, and I would like to create some subscriptions to it, involving resources created within the script.

I.E.

   "DbfExtractQueue": {
        "Type": "AWS::SQS::Queue"
    },

    "EtlSubscription": {
        "Type": "AWS::SNS::Subscription",
        "Properties": {
            "Endpoint": { "Fn::GetAtt": ["DbfExtractQueue", "Arn"] },
            "Protocol": "sqs",
            "TopicArn": { "Ref": "EtlNotificationTopicARN" }
        }
    },

The EtlNotificationTopicARN is passed into the script and represents a SNS topic ARN.

like image 885
stefanlz Avatar asked Sep 05 '13 06:09

stefanlz


People also ask

Can anyone subscribe to an SNS topic?

The entities that can subscribe to your SNS topics can be: "Everyone" (anonymous access), users whose endpoint URL, protocol, email address or ARN from a "Subscribe" request match a certain value, specific AWS users or resources and the topic owner.

How many subscriptions can an SNS topic have?

SNS FIFO topics can further unlock application integration use cases that require large ordered fan-out, up to 100 subscribers.

Which of the following is not a supported subscriber for AWS SNS?

Amazon DynamoDB is not a supported Amazon SNS protocol. 2.

Which of the following can subscribe as an endpoint to Amazon SNS topic?

You specify the endpoint using its URL. To subscribe to a topic, you can use the Amazon SNS console, the sns-subscribe command, or the Subscribe API action.


2 Answers

It is now possible to do this directly in native CloudFormation as of November 2016:

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html

Samples from the above documentation.

YAML:

MySubscription:
  Type: AWS::SNS::Subscription
  Properties:
    Endpoint: [email protected]
    Protocol: email
    TopicArn: !Ref 'MySNSTopic'

JSON:

"MySubscription" : {
  "Type" : "AWS::SNS::Subscription",
  "Properties" : {
    "Endpoint" : "[email protected]",
    "Protocol" : "email",
    "TopicArn" : {"Ref" : "MySNSTopic"}
  }
}
like image 58
Eric Hammond Avatar answered Oct 07 '22 16:10

Eric Hammond


It is possible now since CloudFormation supports Custom Resource Types with Lambda functions.

I've created a gist here with CloudFormation tamplate: https://gist.github.com/martinssipenko/4d7b48a3d6a6751e7464.js

like image 44
msipenko Avatar answered Oct 07 '22 15:10

msipenko