【问题标题】:Cloudformation template - how do i get the value of a computed propertyCloudformation 模板 - 我如何获取计算属性的值
【发布时间】:2018-05-17 04:46:51
【问题描述】:

在以下 Cloudformation 模板中,我正在创建 SES 接收规则。 在其中我计算要通知的 SNS TopicArn。 我想输出该值,但我无法使用语法来获取它。 所有其他输出都是模板参数。

回答:- 在调用模板上设置它并将其作为参数传递:-

Resources:
  ReceiptRule:
    Type: 'AWS::SES::ReceiptRule'
    Properties:
      RuleSetName: !Ref ReceiptRuleSetName
      Rule:
        Name: !Ref RuleName
        Enabled: !Ref RuleEnabled
        ScanEnabled: !Ref RuleScanEnabled
        TlsPolicy: !Ref RuleTLSPolicy
        Recipients:
          - !Ref RuleRecipients
        Actions:
          - S3Action:
              ObjectKeyPrefix: !Ref RuleS3ActionObjectKeyPrefix
              BucketName: !Ref RuleS3ActionObjectBucketName
              TopicArn: !Join [ '',
               [
               !Sub 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:',
               !Ref RuleS3ActionObjectSNSTopic
               ]
               ]
Outputs:
  Recipients:
    Value: !Sub ${RuleRecipients}
  S3Bucket:
    Value: !Sub ${RuleS3ActionObjectBucketName}
  S3Prefix:
    Value: !Sub ${RuleS3ActionObjectKeyPrefix}
  SNSTopicArn:
    Value: >--What do i put here<--

答案:-

RuleS3ActionObjectSNSTopic: !Join [ '',
               [
               !Sub 'arn:aws:sns:${AWS::Region}:${AWS::AccountId}:',
               !FindInMap [ SourceMap, !Ref rr5 , snstopic ]
               ]
               ]

然后模板变成

Resources:
      ReceiptRule:
        Type: 'AWS::SES::ReceiptRule'
        Properties:
          RuleSetName: !Ref ReceiptRuleSetName
          Rule:
            Name: !Ref RuleName
            Enabled: !Ref RuleEnabled
            ScanEnabled: !Ref RuleScanEnabled
            TlsPolicy: !Ref RuleTLSPolicy
            Recipients:
              - !Ref RuleRecipients
            Actions:
              - S3Action:
                  ObjectKeyPrefix: !Ref RuleS3ActionObjectKeyPrefix
                  BucketName: !Ref RuleS3ActionObjectBucketName
                  TopicArn: !Ref RuleS3ActionObjectSNSTopic
    Outputs:
      Recipients:
        Value: !Sub ${RuleRecipients}
      S3Bucket:
        Value: !Sub ${RuleS3ActionObjectBucketName}
      S3Prefix:
        Value: !Sub ${RuleS3ActionObjectKeyPrefix}
      SNSTopicArn:
        Value: !Sub ${RuleS3ActionObjectSNSTopic}

【问题讨论】:

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


    【解决方案1】:

    考虑到主题是作为模板参数传递的,您可以:

    1. 接受 SNSTopicArn 作为参数,而不仅仅是要求主题名称

    2. 您可以像在 ReceiptRule 中那样在输出部分构建 ARN。嗯,不完全是,因为有更好的方法。事实上,你几乎就在那里。下面是它的样子:

    --

    Outputs:
      SNSTopicArn:
        Value: !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${RuleS3ActionObjectSNSTopic}"
    

    --

    请注意,使用内部函数 Fn::GetAtt 不会起作用,因为 SNS 资源不是在同一个模板中创建的。

    【讨论】:

    • 使用您的选项 1. 更新问题 - 感谢您的帮助!
    猜你喜欢
    • 2022-08-18
    • 2016-09-04
    • 2018-07-21
    • 2021-10-29
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    相关资源
    最近更新 更多