84

Here's (the DynamoDB part of) my Troposphere-generated JSON:

"sandbox": {
        "Properties": {
            "AttributeDefinitions": [
                {
                    "AttributeName": "audit_id",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "status",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "filename",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "file_detected_dt",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "time_taken",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "number_rows_processed_file",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "number_rows_created_db",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "info_messages",
                    "AttributeType": "S"
                }
            ],
            "KeySchema": [
                {
                    "AttributeName": "audit_id",
                    "KeyType": "HASH"
                }
            ],
            "ProvisionedThroughput": {
                "ReadCapacityUnits": {
                    "Ref": "ReadCapacityUnits"
                },
                "WriteCapacityUnits": {
                    "Ref": "WriteCapacityUnits"
                }
            }
        },
        "Type": "AWS::DynamoDB::Table"
    }

CloudFormation gives me this error on trying to spin up the VPC: Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes.

But ... is it? I'm specifying audit_id as a lone key, and it definitely exists within the AttributeDefinitions list. I'm very new to CF (and Dynamo, for that matter) so I may well be missing something extremely obvious, but it's not apparent to me at the moment.

I've googled around and only really found one mention of this error, and it was more to do with a layer between developer and CF, rather than CF itself.

Can anyone point out what's wrong with my template?

user1381745
  • 3,850
  • 2
  • 21
  • 35
  • CloudFormation Linter rule to help catch this quicker with more information: https://github.com/aws-cloudformation/cfn-python-lint/pull/1284 – Pat Myron Jan 08 '20 at 17:53

1 Answers1

179

This was down to a misunderstanding on my part regarding DynamoDB. The only attributes that should be defined here are those that will be used as keys. Thus, changing the AttributeDefinitions array to the following solved the problem:

"AttributeDefinitions": [
            {
                "AttributeName": "audit_id",
                "AttributeType": "S"
            }
]
user1381745
  • 3,850
  • 2
  • 21
  • 35
  • 3
    This is also captured [here](http://stackoverflow.com/a/30924384/1111215) – Benny Bauer Sep 22 '16 at 11:27
  • 10
    The mistake here was trying to define the schema of the table (i.e. the 'columns' of the table in relational DB speak). In DynamoDb you only define the key with which to retrieve the values of the item in the table, not the schema of the item itself. DynamoDb is schemaless, and the values stored against each key is defined when the item is added. There is no data shape to define. – Zodman Jan 19 '18 at 07:11
  • @Zodman Thanks a lot for your comment specially this part: " DynamoDb is schemaless, and the values stored against each key is defined when the item is added. There is no data shape to define" – Hamed Minaee Jan 19 '18 at 18:24
  • 3
    Oh man, I was stuck on this exact same problem for ages. Thanks. – blueprintchris Mar 26 '18 at 11:30
  • 3
    Not every hero wear capes...Thanks for the catch ! – Marcello Grechi Lins Apr 20 '18 at 00:25
  • Thanks! Had exactly this misunderstanding too. – stef Sep 05 '19 at 19:14