cassiius
cassiius

Reputation: 43

CloudFormation - Create SNS subscription in disabled state

Is there a way to create an SNS subscription in the disabled state? This is for a lambda if that makes a difference.

Example:

MySubscription:
  Type: AWS::SNS::Subscription
  Properties:
    Endpoint: arn:aws:lambda:region:account-id:function:mylambda
    Protocol: lambda
    TopicArn: arn:aws:sns:region:account-id:topic
    Enabled: false # like this

Couldn't find anything like this in the AWS CloudFormation documentation

Upvotes: 4

Views: 2053

Answers (2)

Bruno Silva
Bruno Silva

Reputation: 618

You can create a condition on the subscription creation.

First add a parameter:

   "CreateSubscription": {
      "Type": "String",
      "AllowedValues": [
        "true",
        "false"
      ],
      "Description": "Create subscription to sns"
    }

after the 'parameters' section, create a 'conditions' section:

"Conditions" : {
    "CreateSubscription" : {"Fn::Equals" : [{"Ref" : "CreateSubscription"}, "true"]}
  }

add the condition to your subscription

"Subscription": {
      "Type": "AWS::SNS::Subscription",
      "Condition" : "CreateSubscription",
      [...]
}

when you want to "activate" you subscription, you just have to change the parameter value updating the stack using the same template

Conditions section reference

Upvotes: 4

Himal
Himal

Reputation: 3512

There isn't a way with Cloudformation which conforms to your example. According to the documentation, AWS::SNS::Subscription does not have 'Enabled' as a setting.

Although, the documentation does state that the owner of the endpoint must confirm the subscription before Amazon SNS creates the subscription. So, in a sense, it's already disabled because it doesn't exist until you confirm it on the SNS topic.

Upvotes: 3

Related Questions