amazon-cloudformation - 在 AWS SAM 模板中出现 Fn::GetAtt 错误
问题描述
我已经在我的 AWS 无服务器应用程序模型模板中声明了 SNS 主题和订阅,如下所示:-
MyTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: !Sub 'test-${Environment}-${AWS::AccountId}-${AWS::Region}'
Tags:
- Key: Environment
Value: !FindInMap [Environment, FullForm, !Ref Environment]
TopicName: !Sub 'test-${Environment}-${AWS::AccountId}-${AWS::Region}'
MySubscription:
Type: AWS::SNS::Subscription
Properties:
Endpoint: !Ref SubscriptionEndPoint
Protocol: !Ref SubscriptionProtocol
Region: !Ref 'AWS::Region'
TopicArn: !Ref MyTopic
然后在我的 Lambda 函数环境中使用 SNS 主题 ARN,如下所示在同一个模板文件中:-
MyLambda:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
RUNTIME_SNS_TOPIC_ARN: !GetAtt MyTopic.Arn
输出(在 SAM 模板中):-
MyTopic:
Description: SNS Topic for the Ingest to send notification to
Export:
Name: !Sub
- ${ExportPrefix_}:${AWS::Region}:MyTopic
- ExportPrefix_: !If
- HasExportPrefix
- !Join ['-', [!Ref ExportPrefix, !Ref Environment]]
- !Join ['-', [!Select [0, !Split ["-", !Ref "AWS::StackName"]], !Ref Environment]]
Value: !Sub "${MyTopic.Arn}:${MyTopic.Version.Version}"
MySubscription:
Description: Subscription to get messages from a topic
Export:
Name: !Sub
- ${ExportPrefix_}:${AWS::Region}:MySubscription
- ExportPrefix_: !If
- HasExportPrefix
- !Join ['-', [!Ref ExportPrefix, !Ref Environment]]
- !Join ['-', [!Select [0, !Split ["-", !Ref "AWS::StackName"]], !Ref Environment]]
Value: !Sub "${MySubscription.Arn}:${MySubscription.Version.Version}"
但是,我收到以下错误:-
13:30:30 错误:无法为堆栈创建变更集:my-stack,例如:Waiter ChangeSetCreateComplete 失败:Waiter 遇到终端故障状态状态:FAILED。原因:模板错误:资源 MyTopic 不支持 Fn::GetAtt 中的属性类型 Arn
解决方案
AnAWS::SNS:Topic
在您使用时返回 ARNRef
查看有关返回值的文档。
尝试
MyLambda:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
RUNTIME_SNS_TOPIC_ARN: !Ref MyTopic # Using !Ref
推荐阅读
- c# - 验证服务描述符“ServiceType ...”时出错
- python - 从更新的数据框中识别修改的行
- javascript - Javascript 搜索延迟并从事件监听器收集输入
- angular - 反应形式:不能绑定到“formGroup”,因为它不是“form”的已知属性
- excel - 使用索引匹配从日期中获取所需的结果
- r - 如何在 R 中组合 sf 元素(层)
- arrays - 这个反汇编的数组的开始和结束是什么?
- flutter - 如何使用自定义画家在 Flutter 中为容器绘制尾部
- kubernetes - Istio 入口网关随机返回 507 响应
- python - 传递给范围python循环中的下一个数字