代码之家  ›  专栏  ›  技术社区  ›  nad87563

Cloudformation SNS模板验证错误

  •  0
  • nad87563  · 技术社区  · 7 年前

    我正在尝试创建sns订阅,但收到模板验证错误。

    “mysntopic”是名为testsnstopic的cloudformation堆栈的逻辑ID。

    这是正确的吗。有人能解释一下我应该给这里的“Ref”加什么值吗

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

    模板验证错误:

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

    代码:

    {
    "Resources": {
    "MySubscription" : {
      "Type" : "AWS::SNS::Subscription",
      "Properties" : {
        "Endpoint" : "test@abc.com",
        "Protocol" : "email",
        "TopicArn" : {
        "Ref": "MySNSTopic"
        }
      }
    }
    }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   jens walter    7 年前

    要跨不同堆栈使用属性,需要显式导出一端的值并导入到另一个堆栈中。

    在你的情况下,你可能需要这样的东西:

    堆栈:sns测试

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

    堆栈:sns订阅

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