1
votes

I have a fairly simple cloudformation template. I am trying to learn about them. I created one where I am trying to create 2 dyanmo table when I deploy the stack. But only one table gets created. Not two. I am not sure what is wrong with my syntax. Pasting the json below

"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
You have two keys ResourcesMaria Ines Parnisari
Tip: YAML format often avoids problems caused by JSON format. None of those pesky {braces}!John Rotenstein

2 Answers

3
votes

There are few mistakes in the template. One already pointed out by @MariaInesParnisari.

The other ones are missing open bracket and unneeded brackets in the middle.

I fixed the template and can confirm it works:

{
  "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
votes

More generally, the CloudFormation Linter can help catch these template issues faster with errors like:

E0000 Duplicate found "Resources" (line 35)