【问题标题】:Invalid template resource property "Tags"无效的模板资源属性“标签”
【发布时间】:2020-05-15 10:30:16
【问题描述】:

对于以下cloudformation模板:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Some Stack",
    "Parameters":{
        "VpcId":{
            "Type": "AWS::EC2::VPC::Id",
            "Description": "The target VPC Id"
        },
        "SubnetId":{
            "Type": "AWS::EC2::Subnet::Id",
            "Description": "The target subnet Id"
        },
        "KeyName": {
            "Type": "String",
            "Description": "The key pair that is allowed SSH access"
        }
    },
    "Resources":{
        "EcsCluster":{
            "Type": "AWS::ECS::Cluster",
            "Tags": [ 
                        {
                            "Key": "Name",
                            "Value": { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-ecs-cluster" ] ] }     
                        },
                        {
                            "Key": "workenv",
                            "Value": "dev"
                        },
                        {
                            "Key": "abc",
                            "Value": "some_value"
                        },
                        {
                            "Key": "function",
                            "Value": "someapp"
                        },
                        {
                            "Key": "owner",
                            "Value": "email@abc.com"
                        }
            ]
        }
    },
    "Outputs":{
        "ElbDomainName":{
            "Description": "Public DNS name of Elastic Load Balancer",
            "Value": {
                "Fn::GetAtt": [
                    "ElasticLoadBalancer",
                    "DNSName"
                ]
            }
        }
    }
}

以下是错误:

   Invalid template resource property 'Tags'

我按照以下文档添加标签:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html


为什么 CloudFormation 服务不接受在每个资源上定义的Tags?跟缩进有关系吗?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    这是因为 Tags 没有为 EcsCluster 资源正确定义。 Tags 属性应在 Properties 部分中定义,就像您为其他资源定义 Tags 的方式一样。

    "EcsCluster": {
      "Type": "AWS::ECS::Cluster",
      "Properties": {
        "Tags": []
      }
    }
    

    希望这会有所帮助。

    【讨论】:

    • AWS::IAM::InstanceProfile 是否支持Tags?
    【解决方案2】:

    并非所有资源类型都支持标签。检查每种资源类型的文档。

    【讨论】:

    • AWS::IAM::InstanceProfile 不支持Tags 属性,但删除它后,我仍然看到错误。查询已相应编辑
    • 我建议使用 linter,例如 cfn-lint。它可以很好地告诉您出了什么问题。
    • cfn-lint 说 Template valid!,但 AWS 控制台仍然报错。
    • 在这种情况下,cfn-lint 中存在错误(更有可能)或 CloudFormation 中存在错误。我会联系支持人员。
    • @overexchange 尝试从pip安装cfn-lint:github.com/aws-cloudformation/cfn-python-lint
    猜你喜欢
    • 2020-10-21
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2018-03-26
    • 1970-01-01
    相关资源
    最近更新 更多