UUIDs for DynamoDB?

前端 未结 6 1070
滥情空心
滥情空心 2020-12-14 00:02

Is it possible to get DynamoDB to automatically generate unique IDs when adding new items to a table?

I noticed the Java API mentions @DynamoDBAutoGeneratedKey so I\

6条回答
  •  时光取名叫无心
    2020-12-14 01:02

    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;
    }
    

提交回复
热议问题