0
votes

I get the following error when I try to load this cloudformation template to create a dynamo db table

Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "TableName": {
      "Description": "Table name to use",
      "Type": "String",
      "Default": "test-user-unique-ids"
    },
    "ReadCapacityUnits": {
      "Description": "Provisioned read throughput",
      "Type": "Number",
      "Default": "100",
      "MinValue": "1",
      "MaxValue": "10000",
      "ConstraintDescription": "must be between 1 and 10000"
    },
    "WriteCapacityUnits": {
      "Description": "Provisioned write throughput",
      "Type": "Number",
      "Default": "100",
      "MinValue": "1",
      "MaxValue": "10000",
      "ConstraintDescription": "must be between 1 and 10000"
    }
  },
  "Resources": {
    "testUserUniqueIds": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "TableName": {
          "Ref": "TableName"
        },
        "AttributeDefinitions": [
          {
            "AttributeName": "unique_id",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "guid",
            "KeyType": "HASH"
          }
        ],
        "ProvisionedThroughput": {
          "ReadCapacityUnits": {
            "Ref": "ReadCapacityUnits"
          },
          "WriteCapacityUnits": {
            "Ref": "WriteCapacityUnits"
          }
        }
      }
    }
  }
}
1

1 Answers

0
votes

The attribute name is defined as unique_id. However, the hash key has been defined for attribute guid.

The attribute names defined on AttributeDefinitions and the same should be used on KeySchema. They should be consistent.

Either keep unique_id or guid on both AttributeDefinitions and KeySchema.

Edit:

While creating the Dynamodb table, you can include only key attributes such as partition key and sort key if available. The whole concept of nosql database is that each item I.e. record can have different attributes. You don't need to define the non key attributes while creating the table. NoSQL is a schema less database.

If you specify any non key attributes while creating the table, you will get validation exception.