【问题标题】:Cloudformation template with multiple resources具有多种资源的 Cloudformation 模板
【发布时间】:2020-10-17 15:33:52
【问题描述】:

我有一个相当简单的 cloudformation 模板。我正在努力了解他们。我创建了一个在部署堆栈时尝试创建 2 个 dyanmo 表的位置。但是只创建了一张表。不是两个。我不确定我的语法有什么问题。粘贴下面的json

"AWSTemplateFormatVersion" : "2010-09-09",
“资源” : {
  “资源1”:{
    "类型" : "AWS::DynamoDB::Table",
    “特性” : {
      “属性定义”:[
        {
          “属性名称”:“名称”,
          “属性类型”:“S”
        },
        {
          “属性名”:“年龄”,
          “属性类型”:“S”
        }
      ],
      “密钥架构”:[
        {
          “属性名称”:“名称”,
          “密钥类型”:“哈希”
        },
        {
          “属性名”:“年龄”,
          “键类型”:“范围”
        }
      ],
      “预置吞吐量”:{
        "ReadCapacityUnits" : "5",
        “写容量单位”:“5”
      },
      “表名”:“tablecloudformation3_1”
    }
  }
},
“资源” : {
  “资源2”:{
    "类型" : "AWS::DynamoDB::Table",
    “特性” : {
      “属性定义”:[
        {
          “属性名称”:“名称”,
          “属性类型”:“S”
        },
        {
          “属性名”:“年龄”,
          “属性类型”:“S”
        }
      ],
      “密钥架构”:[
        {
          “属性名称”:“名称”,
          “密钥类型”:“哈希”
        },
        {
          “属性名”:“年龄”,
          “键类型”:“范围”
        }
      ],
      “预置吞吐量”:{
        "ReadCapacityUnits" : "5",
        “写容量单位”:“5”
      },
      “表名”:“tablecloudformation3_2”
    }
  }
},
}

【问题讨论】:

  • 你有两个键Resources
  • 提示:YAML 格式往往可以避免 JSON 格式带来的问题。没有那些讨厌的{大括号}!

标签: amazon-cloudformation aws-cloudformation-custom-resource


【解决方案1】:

更一般地说,CloudFormation Linter 可以帮助更快地发现这些模板问题,并出现以下错误:

E0000 Duplicate found "Resources" (line 35)

【讨论】:

    【解决方案2】:

    模板中有几个错误。 @MariaInesParnisari 已经指出了这一点。

    其他的缺少左括号和中间不需要的括号。

    我修复了模板并且可以确认它有效

    {
      "AWSTemplateFormatVersion" : "2010-09-09",
      "Resources" : {
        "resource1" : {
          "Type" : "AWS::DynamoDB::Table",
          "Properties" : {
            "AttributeDefinitions" : [
              {
                "AttributeName" : "Name",
                "AttributeType" : "S"   
              },
              {
                "AttributeName" : "Age",
                "AttributeType" : "S"
              }
            ],
            "KeySchema" : [
              {
                "AttributeName" : "Name",
                "KeyType" : "HASH"
              },
              {
                "AttributeName" : "Age",
                "KeyType" : "RANGE"
              }
            ],
            "ProvisionedThroughput" : {
              "ReadCapacityUnits" : "5",
              "WriteCapacityUnits" : "5"
            },
            "TableName" : "tablecloudformation3_1"
          }
        },
        "resource2" : {
          "Type" : "AWS::DynamoDB::Table",
          "Properties" : {
            "AttributeDefinitions" : [
              {
                "AttributeName" : "Name",
                "AttributeType" : "S"   
              },
              {
                "AttributeName" : "Age",
                "AttributeType" : "S"
              }
            ],
            "KeySchema" : [
              {
                "AttributeName" : "Name",
                "KeyType" : "HASH"
              },
              {
                "AttributeName" : "Age",
                "KeyType" : "RANGE"
              }
            ],
            "ProvisionedThroughput" : {
              "ReadCapacityUnits" : "5",
              "WriteCapacityUnits" : "5"
            },
            "TableName" : "tablecloudformation3_2"
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-24
      • 1970-01-01
      • 2021-04-22
      • 2016-09-30
      • 2021-08-20
      • 1970-01-01
      • 2017-05-05
      • 2019-08-24
      • 1970-01-01
      相关资源
      最近更新 更多