Amazon-CloudFormation [SOLVED]: Cloudformation SNS template validation error

Amazon-CloudFormation [SOLVED]: Cloudformation SNS template validation error

Home Forums Amazon Web Services Amazon CloudFormation Amazon-CloudFormation [SOLVED]: Cloudformation SNS template validation error

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #247029

    Cloudy Point
    Keymaster

    QuestionQuestion

    I am trying to create sns subscription but I am getting template validation error.

    ‘MySNSTopic’ is the Logical ID of the cloudformation stack called testsnstopic.

    Is this correct. Can anyone explain what value I should give for ‘Ref’ here

    "TopicArn" : {
            "Ref": "MySNSTopic"
            }
    

    Template validation error:

    Template format error: Unresolved resource dependencies [MySNSTopic] in the Resources block of the template
    

    code:

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

    #247030

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    To use properties across different stacks, you need to explicitly export the values on the one end and import into the other stack.

    In your case you would propably need something like this:

    Stack: sns-test

    {
        "Resources": {
            "MySNSTopic": {
                "Type": "AWS::SNS::Topic"
            }
        },
        "Outputs": {
            "MySNSTopicOutput": {
                "Description": "SNS topic arn",
                "Value": {
                    "Ref": "MySNSTopic"
                },
                "Export": {
                    "Name": {
                        "Fn::Sub": "${AWS::StackName}-MySNSTopicExport"
                    }
                }
            }
        }
    }
    

    Stack: sns-subscription

    {
      "Resources": {
        "MySubscription": {
          "Type": "AWS::SNS::Subscription",
          "Properties": {
            "Endpoint": "jens@apimeister.com",
            "Protocol": "email",
            "TopicArn": {
              "Fn::ImportValue" : "sns-test-MySNSTopicExport"
            }
          }
        }
      }
    }
    

    Source: https://stackoverflow.com/questions/47917472/cloudformation-sns-template-validation-error
    Author: jens walter
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.