11

Is there an option in DynammoDB to store auto incremented ID as primary key in tables? I also need to store the server time in tables as the "created at" fields (eg., user create at). But I don't find any way to get server time from DynamoDB or any other AWS services.

Can you guys help me with,

  1. Working with auto incremented IDs in DyanmoDB tables
  2. Storing server time in tables for "created at" like fields.

Thanks.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178

3 Answers3

10

Actually, there are very few features in DynamoDB and this is precisely its main strength. Simplicity.

  • There are no way automatically generate IDs nor UUIDs.
  • There are no way to auto-generate a date

For the "date" problem, it should be easy to generate it on the client side. May I suggest you to use the ISO 8601 date format ? It's both programmer and computer friendly.

Most of the time, there is a better way than using automatic IDs for Items. This is often a bad habit taken from the SQL or MongoDB world. For instance, an e-mail or a login will make a perfect ID for a user. But I know there are specific cases where IDs might be useful.

In these cases, you need to build your own system. In this SO answer and this article from DynamoDB-Mapper documentation, I explain how to do it. I hope it helps

Community
  • 1
  • 1
yadutaf
  • 6,840
  • 1
  • 37
  • 48
8

Rather than working with auto-incremented IDs, consider working with GUIDs. You get higher theoretical throughput and better failure handling, and the only thing you lose is the natural time-order, which is better handled by dates.

Higher throughput because you don't need to ask Dynamo to generate the next available IDs (which would require some resource somewhere obtaining a lock, getting some numbers, and making sure nothing else gets those numbers). Better failure handling comes when you lose your connection to Dynamo (Dynamo goes down, or you are bursty and your application is doing more work than currently provisioned throughput). A write-only application can continue "working" and generating data complete with IDs, queueing it up to be written to dynamo, and never worry about ID collisions.

Cory Kendall
  • 7,195
  • 8
  • 37
  • 64
0

I've created a small web service just for this purpose. See this blog post, that explains how I'm using stateful.co with DynamoDB in order to simulate auto-increment functionality: http://www.yegor256.com/2014/05/18/cloud-autoincrement-counters.html

Basically, you register an atomic counter at stateful.co and increment it every time you need a new value, through RESTful API.

yegor256
  • 102,010
  • 123
  • 446
  • 597