【问题标题】:How to export SNS topic to be used in different stacks in Cloudformation如何导出 SNS 主题以在 Cloudformation 中的不同堆栈中使用
【发布时间】:2018-08-06 03:51:44
【问题描述】:

在一个 Cloudformation 模板中,我创建了一个 SNS 主题并将其导出。请注意,您无法导出 SNS 主题的 Arn,因为该属性不适用于 docs 上的 GetAtt

BaseStack

Outputs:
  AlarmSNSTopic: 
    Description: Arn for SNS topic related to alarms
    Export:
      Name: AlarmSNSTopic
    Value: { "Fn::GetAtt": ["MyAlarmSNSTopic", "TopicName"] }

然后在另一个模板中,我尝试使用以下内容引用该导出:

功能栈 1

InputQueueNoMessages:
  Type: AWS::CloudWatch::Alarm
  Properties:
    AlarmDescription: Some Alarm
  ...
  AlarmActions:
    Fn::ImportValue: AlarmSNSTopic

当我这样做时,Cloudformation 告诉我它需要一个 ARN,而不是主题名称。

Invalid arn syntax: Blah-AlarmSNSTopic-random

这可能吗?我错过了什么吗?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation amazon-sns


    【解决方案1】:

    AWS::CloudWatch::Alarm 需要 AlarmActions 的 ARN,但您导出了主题名称。您的输出值应该是 ARN。

    Outputs:
      AlarmSNSTopic: 
        Description: Arn for SNS topic related to alarms
        Export:
          Name: AlarmSNSTopic
        Value: !Ref MyAlarmSNSTopic
    

    【讨论】:

      【解决方案2】:

      只需做一个参考,它会返回主题 ARN。

      Value: !Ref MyAlarmSNSTopic
      

      参考

      对于 AWS::SNS::Topic 资源,Ref 内部函数 返回主题 ARN,例如: arn:aws:sns:us-east-1:123456789012:mystack-mytopic-NZJ5JSMVGFIE。

      https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html#w2ab2c21c10d983c11

      【讨论】:

      • 你不能reference 在不同的堆栈中创建资源而不导出它们,除非我弄错了?例如aws.amazon.com/blogs/aws/…
      • 你可以在导出时做一个 ref 而不是 getatt
      猜你喜欢
      • 2016-03-23
      • 2016-04-19
      • 2020-10-31
      • 2021-06-18
      • 2021-05-14
      • 2020-09-11
      • 2017-12-14
      • 2018-03-01
      • 1970-01-01
      相关资源
      最近更新 更多