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?
JSON has no sets, just arrays, so DynamoDB sets (SS, NS, and BS types) will be converted to JSON arrays. JSON has no binary representation, so DynamoDB binary scalars and sets (B and BS types) will be converted to base64-encoded JSON strings or lists of strings.
You can store a JSON document as an attribute in a DynamoDB table. To do this, use the withJSON method of Item . This method parses the JSON document and maps each element to a native DynamoDB data type.
To get an AWS AppSync schema to handle nested JSON data in DynamoDB, do the following: Add a nested JSON data item to the DynamoDB table. Create an AWS AppSync API and attach the data source. Configure the nested JSON schema in the AWS AppSync API.
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" } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With