Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamo DB Increment/Unique id generation

In AWS Dynamo DB we would like to automatically generate a unique id for our primary key when we call our update/put spotid function:

dynamodb.put_item(
    TableName = tablesinfo, Item = {
      'spot_id':{'N' : spot_id},
      'latitude':{'N' : lat},
      'longitude':{'N' : lon},
      'description':{'S' : descrip}
      }

Note code is in Python but since we plan on using AWS Lambda for this we can also use Java or Node.JS, However we would prefer if DynamoDB could handle this function.

like image 212
Y Anderson Avatar asked Feb 25 '16 07:02

Y Anderson


People also ask

Does DynamoDB auto generate ID?

DynamoDB does not support auto-incrementing IDs for items. They can be a performance bottleneck at scale, and most workloads are better off with UUIDs anyway. However, there are use cases where auto-incrementing integers are required.

Can we have multiple GSI in DynamoDB?

Some applications might need to perform many kinds of queries, using a variety of different attributes as query criteria. To support these requirements, you can create one or more global secondary indexes and issue Query requests against these indexes in Amazon DynamoDB.

How do I enable auto scaling in DynamoDB?

Choose the table that you want to work with and select the Additional settings tab. In the Read/write capacity section, select Edit. In the Capacity mode section, select Provisioned. In the Table capacity section, set Auto scaling to On for Read capacity, Write capacity, or both.

Does DynamoDB GSI need to be unique?

DynamoDB Global Secondary Index (GSI) Most of the time, you'll find yourself using GSIs over LSIs because they enable much more flexible query access patterns. Moreover, GSIs: Don't have that 10GB of data per Hash/Partition Key limit like LSIs have. Global Secondary Indexes don't have to be unique!


1 Answers

DynamoDb will not generate any primary keys for you (one of the many ways it differs from relational databases).

You could just generate a unique id in code when you put an item. Java/Node/Python all have ways of generating GUIDs/UUIDs.

Check out this question to find out how to do it in Python: How to create a GUID/UUID in Python.

like image 145
routeburn Avatar answered Sep 29 '22 10:09

routeburn