Updating an Item in Dynamo DB Table

I have recently started working in DynamoDB.

While going through Developer Guide and various tutorials about updating an Item in Table, what I understand is that whenever we update an Item, It first check whether that Item is present in the Table or not. If present it will update that Item, otherwise it will create a new Item and insert it.

Now, My doubt is how does it check about the availability of Item in Table.

Is it on the basis of primary key only ?

Well, I tried to code it, and what I found was interesting that If I will change any of the key attibute (GSI,LSI). It just creates a new Item.

So what should I do to update GSI/LSI of any Item ?

Let me elaborate it using an example, Say I have a Table named TEST. The schema of table is :

ID(PK/HK) - "101"
Date(RK) -"200415"
Name(GSI) -"foo"
Add(LSI) -"foo1"
orderNo(normal attribute ) -"foo2"

So when I tried to update orderNo as "foo3" it is working fine. It just updates the table as:

ID(PK/HK) - "101"
Date(RK) -"200415"
Name(GSI) -"foo"
Add(LSI) -"foo1"
orderNo(normal attribute ) -"foo3"

But If I try to change some key attribute say add as "some add ". It creates a new Item and my Table now consists of two items:

ID(PK/HK) - "101"
Date(RK) -"200415"
Name(GSI) -"foo"
Add(LSI) -"foo1"
orderNo(normal attribute ) -"foo3"


ID(PK/HK) - "101"
Date(RK) -"200415"
Name(GSI) -"foo"
Add(LSI) -"some add"
orderNo(normal attribute ) -"foo3"

A solution to solve this issue may be Deleting that Item and then insertin a new Item.

Isn’t there any other way to solve this ?

Note:
Some abbreviations used :

PK – Primary Key

HK – Hash Key

RK – Range Key

GSI – Global Secondary Key

LSI – Local Secondary Key

I am using java as my programming language.


Source: java

Leave a Reply