gpt4 book ai didi

amazon-web-services - Cloudformation 模板 - 如何获取计算属性的值

转载 作者:行者123 更新时间:2023-12-03 07:37:04 24 4
gpt4 key购买 nike

在以下 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}

最佳答案

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

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

  2. 您可以像在 ReceiptRule 中一样在“输出”部分中构建 ARN。嗯,不完全是,因为有更好的方法。事实上你就快到了。它可能如下所示:

--

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

--

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

关于amazon-web-services - Cloudformation 模板 - 如何获取计算属性的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50378055/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com