Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 517
user1381745 Avatar asked Jul 01 '16 10:07

user1381745


People also ask

What is the data type for JSON in DynamoDB?

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.

Can JSON be stored in DynamoDB?

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.

Can DynamoDB store nested JSON?

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.


1 Answers

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"             } ] 
like image 132
user1381745 Avatar answered Sep 24 '22 00:09

user1381745