【发布时间】:2019-04-26 16:52:05
【问题描述】:
我正在尝试使用 yaml 模板创建 AWS cloudformation 堆栈。 目标是为一些通知创建一个 sns 主题。 我想输出主题 arn,以便能够通过指定主题 arn 来订阅该主题的多个函数。
但是,当我尝试从 aws 控制台创建堆栈时出现错误:
“模板验证错误:模板错误:资源NotificationsTopic不支持Fn::GetAtt中的属性类型Arn”
我对 s3 存储桶、dynamodb 表进行了完全相同的操作,并且一切正常,但由于某种原因,对于 SNS 主题,我无法获得 ARN。
我想避免在所有订阅的函数中对主题 arn 进行硬编码。因为如果有一天 ARN 主题发生变化,我需要更改所有函数,而不是我想在所有函数中导入主题 arn 并使用它。这样,如果将来出于任何原因我有新的 arn 主题,我将无需修改任何内容。
这是模板:
Parameters:
stage:
Type: String
Default: dev
AllowedValues:
- dev
- int
- uat
- prod
Resources:
NotificationsTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub 'notifications-${stage}'
Subscription:
- SNS Subscription
TopicName: !Sub 'notifications-${stage}'
Outputs:
NotificationsTopicArn:
Description: The notifications topic Arn.
Value: !GetAtt NotificationsTopic.Arn
Export:
Name: !Sub '${AWS::StackName}-NotificationsTopicArn'
NotificationsTopicName:
Description: Notifications topic name.
Value: !Sub 'notifications-${stage}'
Export:
Name: !Sub '${AWS::StackName}-NotificationsTopicName'
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-sns aws-serverless