1

I'm new to Amazon DynamoDB and perhaps my problem is stemming from my SQL knowledge.

I want to have a very simple Form table. That table holds name, date, enquiry. The idea behind this is to capture user submissions via various websites' enquiry forms.

When I setup the table, I was asked for an index, so a sensible choice for me was Client Name. The Client Name was going to be the name of the website which the forms were being sent from.

So I setup the table, created a vagrant machine, and got everything running with Amazon SDK.

However, when I started sending 2 forms to Amazon for the same client, they overwrote each other.

What I'm thinking is that the index needs to be unique to the form, however there isn't a way to auto increment them. Without the auto incrementation, it seems I need to query the database before a insert any data, it seems an odd way to do things.

How do I setup the indexes properly for my situation?

dotty
  • 40,405
  • 66
  • 150
  • 195

2 Answers2

1

In the example above, the table has been created with "name" as the hash key and this is the primary key of the table. Since primary key values need to be unique across all items (i.e. rows) in a DynamoDB table, there can be only one item in the table with the same "name".

Please note that for indexes, the index key (hash attribute or hash and range attribute) values do not need to be unique. For example, you can store multiple items in the index with the same "client name". More details on DynamoDB indexes is available at http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SecondaryIndexes.html.

If the combination of "name" and "date" (assuming the "date" attribute capture timestamp) is unique (this would be true if an user cannot have two inquiries created at the exact same time), you can create the DynamoDB table with "name" as hash attribute and "date" as range attribute. This will allow fetching inquiries of an user based on date range using the Query API. Documentation on DynamoDB Query API is available at http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html.there.

Regards

0

You need an ID field as your primary key. This SO Q&A has one solution to auto incrementing in Dynamodb that uses the atomic counter function. Alternatively you can use a UUID for the ID.

Community
  • 1
  • 1
Ben Whaley
  • 32,811
  • 7
  • 87
  • 85