【问题标题】:How to check undefined resource attribute within CloudFormation template?如何检查 CloudFormation 模板中未定义的资源属性?
【发布时间】:2021-07-19 17:23:03
【问题描述】:

有没有办法在 CloudFormation 模板中检查未定义的资源属性(由 Fn::GetAtt 返回)?

我想使用 Fn::GetAtt 将指定资源的属性包含在堆栈的输出中,前提是这些属性已定义。

例如,使用以下模板创建堆栈会给我一个错误:

属性:找不到资源的 StreamArn:MyTestStack-DDBTable-1C0T2MJZA1J0I。用户请求回滚。

因为该特定表的资源属性中不包含流规范。

当然,解决这个问题的简单方法就是从堆栈输出列表中删除 StreamArn。但是,我仍然想知道如何检查该属性是否是为指定资源定义的。

任何建议都将受到高度赞赏。

  • 拍拍

{
   "Resources":{
      "DDBTable":{
         "Type":"AWS::DynamoDB::Table",
         "Properties":{
            "AttributeDefinitions":[
               {
                  "AttributeName":"ArtistId",
                  "AttributeType":"S"
               },
               {
                  "AttributeName":"Concert",
                  "AttributeType":"S"
               },
               {
                  "AttributeName":"TicketSales",
                  "AttributeType":"S"
               }
            ],
            "GlobalSecondaryIndexes":[
               {
                  "IndexName":"GSI",
                  "KeySchema":[
                     {
                        "AttributeName":"TicketSales",
                        "KeyType":"HASH"
                     }
                  ],
                  "Projection":{
                     "ProjectionType":"KEYS_ONLY"
                  },
                  "ProvisionedThroughput":{
                     "ReadCapacityUnits":5,
                     "WriteCapacityUnits":5
                  }
               }
            ],
            "KeySchema":[
               {
                  "AttributeName":"ArtistId",
                  "KeyType":"HASH"
               },
               {
                  "AttributeName":"Concert",
                  "KeyType":"RANGE"
               }
            ],
            "ProvisionedThroughput":{
               "ReadCapacityUnits":5,
               "WriteCapacityUnits":5
            }
         }
      }
   },
   "Outputs":{
      "DDBTablePhysicalID":{
         "Value":{
            "Ref":"DDBTable"
         }
      },
      "DDBTableArn":{
         "Value":{
            "Fn::GetAtt":[
               "DDBTable",
               "Arn"
            ]
         }
      },
      "DDBTableStreamArn":{
         "Value":{
            "Fn::GetAtt":[
               "DDBTable",
               "StreamArn"
            ]
         }
      }
   }
}

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    仅当定义了这些属性时。

    在普通 CFN 中不支持。您必须通过以 lambda 函数的形式定义自己的 macrocustom resource 来做到这一点。

    【讨论】:

    • 非常感谢您的回答。无论如何,有没有办法只忽略 Fn::GetAtt 失败以防止堆栈回滚并仍然为所有其他类型的故障启用堆栈回滚?
    猜你喜欢
    • 2017-12-23
    • 2021-04-22
    • 2019-08-24
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多