代码之家  ›  专栏  ›  技术社区  ›  fgonzalez

AWS cloudformation错误:模板验证错误:模板错误:资源通知STOPIC不支持Fn::GetAtt中的属性类型Arn

  •  2
  • fgonzalez  · 技术社区  · 7 年前

    我正在尝试使用yaml模板创建AWS cloudformation堆栈。 目标是为一些通知创建一个sns主题。 我想输出主题arn,通过指定主题arn就可以订阅该主题的多个函数。

    但是,当我尝试从aws控制台创建堆栈时,出现了一个错误:

    “模板验证错误:模板错误:资源通知STOPIC不支持Fn::GetAtt中的属性类型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'
    
    1 回复  |  直到 7 年前
        1
  •  33
  •   petrch    5 年前

    并非所有资源都是相同的。始终检查特定资源的文档。它有“返回值”部分,您可以轻松验证SNS主题是否将ARN作为 Ref 值,因此您不必使用 GetAtt 功能

    https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html

    编辑:感谢您的评论,它指出并不是每个资源都提供其ARN。一个显著的例子是自动缩放组。当然,我回答的关键是“检查每个资源的文档”,这是一个不是每个资源都有每个属性的示例。 https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/548 和 https://github.com/aws/containers-roadmap/issues/631#issuecomment-648377011 但我认为这是一个非常重要的问题,应该在这里提及。

        2
  •  1
  •   aboitier    5 年前

    对于不直接返回ARN的资源,我找到了一个解决方案,包括自己构建ARN。

    例如,要获取代码管道的ARN:

    !Join [ ':', [ "arn:aws:codepipeline", !Ref AWS::Region, !Ref AWS::AccountId, !Ref StackDeletePipeline ] ]