在以下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}
答案 0 :(得分:0)
考虑到主题作为模板参数传递,您可以:
接受SNSTopicArn作为参数,而不是只询问主题名称
您可以像在ReceiptRule中一样在Outputs部分中构建ARN。嗯,不完全是,因为有更好的方法。事实上,你几乎就在那里。这是它的样子:
-
Outputs:
SNSTopicArn:
Value: !Sub "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${RuleS3ActionObjectSNSTopic}"
-
请注意,由于未在同一模板中创建SNS资源,因此使用内在函数Fn::GetAtt
将无效。