具有多种资源的Cloudformation模板

时间:2020-06-27 01:10:05

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

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

"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"
    }
  }
},
"Resources" : {
  "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"
    }
  }
},
}

2 个答案:

答案 0 :(得分:3)

模板中有个错误。 @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"
      }
    }
  }
}

答案 1 :(得分:1)

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

E0000 Duplicate found "Resources" (line 35)