首页 > 解决方案 > 具有多种资源的 Cloudformation 模板

问题描述

我有一个相当简单的 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”
    }
  }
},
}

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

解决方案


模板中的错误很少。@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"
      }
    }
  }
}

推荐阅读