Skip to content
Advertisement

Dynamodb get a single item based on sort key only

I am new to dynamodb and I need to process 5M records. Each record has an id and a status. I need to query for each record based on its status, process it, and finally update the status.

I am using DynamoDbEnhancedClient but I could not find example on how to query based only on the range and not the hash, while avoiding scan. I tried to create a query with a condition and a limit of 1 but it did not work.

Here is what I have:

My Customer model:

JavaScript

configs:

JavaScript

My query:

JavaScript

However that does not work. How can query by status and only get a single result? I have no restriction on the table structure and I can change it however I require.

Advertisement

Answer

So I finally figured it out, I needed to create create a GSI (Global Secondary Index)

When creating the GCI you define the the sort key as hash key and than you can query the index.

create table:

JavaScript

My model in Java:

JavaScript

Than query the db:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement