Search code examples
amazon-dynamodb

Enabling optimistic locking - DynamoDBVersionAttribute on an existing table


I have an existing table in production on which I would like to enable optimistic locking. The documentation here says that the "new" objects will be assigned version number 1.

Now if I add the following attribute to the table, how will this will value be set for an existing item? since my table already contains production data how will the updateItem() operation work?

@DynamoDBVersionAttribute
public Long getVersion() { return version; }
public void setVersion(Long version) { this.version = version;}

Will the first UpdateItem operation assign version = 1 if the existing version value is null?


Solution

  • Yes that's correct, the first update from Null will set the value to 1.

    As always, do a test in a development environment before making any changes to production.