0

I've been working with Vogels and NodeJS - Vogels handles creating the schema for me in DynamoDB local. It works perfect.

For some reason, I'm having problem trying to deploy app in AWS using DynamoDB service. I am getting the error:

Details:TypeError: Cannot read property 'hashKey' of undefined

I have even tried to manually setup the schema however DynamoDB does not have option for hashKey in the AWS Console. It only gives option for:

  • Primary Key/partition (String/Binary/Number)
  • Sort key (String/Binary/Number)

Has anyone come across this or know how to handle creating the schema?

Aaron
  • 2,672
  • 10
  • 28
  • 45

1 Answers1

1

When you say two Primary keys. I presume that you mean hash key and sort key (two separate attributes).

Please note that two attributes can't be part of a hash key.

Hash Key - 1 attribute

Sort Key - 1 attribute

DynamoDB supports two different kinds of primary keys:

Partition Key—A simple primary key, composed of one attribute, known as the partition key. DynamoDB uses the partition key's value as input to an internal hash function; the output from the hash function determine the partition where the item will be stored. No two items in a table can have the same partition key value.

Partition Key and Sort Key—A composite primary key composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key. DynamoDB uses the partition key value as input to an internal hash function; the output from the hash function determines the partition where the item will be stored. All items with the same partition key are stored together, in sorted order by sort key value. It is possible for two items to have the same partition key value, but those two items must have different sort key values.

Primary key

Screenshot for creating the table in AWS console:-

Create table in AWS Console

notionquest
  • 37,595
  • 6
  • 111
  • 105
  • Thank you for your detailed reply. Actually the secondary key I was referring is actually the rangeKey. Is rangeKey the same as sort key? I'm trying to read documentation on AWS but rather difficult to understand. – Aaron Dec 28 '16 at 22:36
  • 1
    Yes, range key is same as sort key. – notionquest Dec 28 '16 at 22:38
  • Wow thank you for such a quick response :) Is there anyway to add this after the tables have been setup? or must I create it from scratch? (just can't see an option adding in console) – Aaron Dec 28 '16 at 22:54
  • No, once the table is created, it can't be altered to include the range or sort key. The new table should be created with the required key attributes. – notionquest Dec 29 '16 at 07:58