UUIDs for DynamoDB?

By using schema based AWS dynamodb data mapper library in Node.js, Hash key (id) will be generated automatically. Auto generated ids are based on uuid v4.

For more details, have a look on following aws package.

Data Mapper with annotation

Data Mapper package for Javascript

Sample snipet

@table('my_table')
class MyDomainClass {
    @autoGeneratedHashKey()
    id: string;

    @rangeKey({defaultProvider: () => new Date()})
    createdAt: Date;
}

Good question - while conceptually possible, this seems not currently available as a DynamoDB API level feature, insofar neither CreateTable nor PutItem refer to such a functionality.

The @DynamoDBAutoGeneratedKey notation you have noticed is a Java annotation, i.e. syntactic sugar offered by the Java SDK indeed:

An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code.

As such @DynamoDBAutoGeneratedKey is one of the Amazon DynamoDB Annotations offered as part of the Object Persistence Model within the Java SDK's high-level API (see Using the Object Persistence Model with Amazon DynamoDB):

Marks a hash key or range key property as being auto-generated. The Object Persistence Model will generate a random UUID when saving these attributes. Only String properties can be marked as auto-generated keys.


While working with dynamodb in javascript with nodejs. I use the npm module uuid to genrate unique key.

Ex:

id=uuid.v1();

refer :uuid npm