Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 866
cassiius Avatar asked Oct 18 '25 21:10

cassiius


2 Answers

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

like image 143
Bruno Silva Avatar answered Oct 21 '25 10:10

Bruno Silva


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.

like image 23
Himal Avatar answered Oct 21 '25 12:10

Himal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!