Question: In my db scheme, I need a autoincrement primary key. How I can realize this feature? 

PS For access to DynamoDB, I use [dynode](https://github.com/Wantworthy/dynode), module for Node.js.

Answer: 
Disclaimer: I am the maintainer of the Dynamodb-mapper project

Intuitive workflow of an auto-increment key:

1. get the last counter position
2. add 1
3. use the new number as the index of the object
4. save the new counter value
5. save the object

This is just to explain the underlying idea. Never do it this way because it's not atomic. Under certain workload, you may allocate the same ID to 2+ different objects because it's not atomic. This would result in a data loss.

The solution is to use the **atomic ADD** operation along with **ALL\_NEW** of [UpdateItem](http://docs.amazonwebservices.com/amazondynamodb/latest/developerguide/API_UpdateItem.html):

1. atomically generate an ID
2. use the new number as the index of the object
3. save the object

In the worst case scenario, the application crashes before the object is saved but never risk to allocate the same ID twice.

There is one remaining problem: where to store the last ID value ? We chose:

```
{
    "hash_key"=-1, #0 was judged too risky as it is the default value for integers.
    "__max_hash_key__y"=N
}

```

Of course, to work reliably, all applications inserting data MUST be aware of this system otherwise you might (again) overwrite data.

the last step is to automate the process. For example: 

```
When hash_key is 0:
    atomically_allocate_ID()
actual_save()

```

For implementation details (Python, sorry), see <https://bitbucket.org/Ludia/dynamodb-mapper/src/8173d0e8b55d/dynamodb_mapper/model.py#cl-67>

To tell you the truth, my company does not use it in production because, most of the time it is better to find another key like, for the user, an ID, for a transaction, a datetime, ...

I wrote some examples in [dynamodb-mapper's documentation](http://dynamodb-mapper.readthedocs.org/en/latest/api/model.html#using-auto-incrementing-index) and it can easily be extrapolate to Node.JS

If you have any question, feel free to ask.
I've had the same problem and created a small web service just for this purpose. See this blog post, that explains how I'm using [stateful.co](http://www.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](http://www.stateful.co) and increment it every time you need a new value, through RESTful API. The service is free.