7

I have been using the command aws dynamodb create-table --cli-input-json to create local dynamodb tables for testing on my local box.

I can create simple tables but I cannot create more complex, real world tables. I looked through the AWS documentation and it's missing the explanation for nested AttributeDefinitions, or I could not find it. Here's a simple example that works (for creation through the AWS CLI):

{
  "TableName": "fruitsTable",
  "KeySchema": [
    {
      "AttributeName": "fruitId",
      "KeyType": "HASH"
    }
  ],
  "AttributeDefinitions": [
    {
      "AttributeName": "fruitId",
      "AttributeType": "S"
    }
  ],
  "ProvisionedThroughput": {
    "ReadCapacityUnits": 5,
    "WriteCapacityUnits": 5
  }
}

That works fine. aws dynamodb create-table --cli-input-json file:///Users/you/subfile/server/config/tables/fruits.json --endpoint-url http://localhost:8000

However I would like to see an example of creating an object that is more complex. What schema would work for this?

{
  "ComplexFruit" : [
    {
      "complexFruitId": "redbanana-fromGroceryStore"
      "name" : "redBanana", 
      "notes": "this one is red",
      "count" : {
        "ripe" : 5,
        "total": 10
       },
      "stores" : [ 
          {"storeName" : "Exito"}
       ]
     }
   ]
}

I am stumped on how I can create a nested AttributeDefinition without a ton of guessing or digging through the code (if dynamodb is open source?). Does anyone know? Also this obviously a contrived example but it would demonstrate how to create nested schemas.

2 Answers 2

5

You only need to specify AttributeDefinitions for attributes that will be part of the table's primary key or part of an index's key. Dynamo is mostly schemaless (other than the key definitons). It doesn't care about any of the other attributes you want to store - there is no need to model anything.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm interesting. Okay I guess this is something I just misunderstood because I come from a SQL world. Thanks.
2

In the spirit learning, I will share some that I have learned, and during the process of learning about DynamoDb, I played with a couple of ORMs.

Dynamoose documentation is terrible, I got it working through a lot of trial and error. AWS documentation is bad but do-able. This is what I was looking for from the beginning https://github.com/awslabs/dynamodb-data-mapper-js

Hopefully this will be a shortcut for other devs looking into using DynamoDb with ORM on Nodejs

1 Comment

I had the exact same feeling about the data-mapper. Dynamoose seems a bit better now, but still has major gaps in the docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.