CloudFormation insists my DynamoDB creation JSON is invalid .. but I can't see how

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?

14591 次浏览

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"
}
]