0

I am using aws-sdk to connect with DynamoDb and I have got into a scenario where I got one dynamodb table with different partition/hash-key and I have to scan and filter to get the results. Scanning the entire table would be a costly operation . Is there a way to scan only a certain partion/haskey of a table ?

1
  • If I understood correctly, you need to look into queries. They allow you to get data based on primary key (partition/hash) Commented Mar 25, 2019 at 14:05

1 Answer 1

2

You have to use Dynamo DB Query. You can query any table or secondary index that has a composite primary key (a partition key and a sort key).

In my opinion you shouldn't use scan, because it very costly and slow.

You didn't write what is the program language, but here is some example to query:

About indices:

UPDATE #1:

Maybe that will help:

  1. Add a new column to your table. The values will be static. (For example: Col name: const_value Values: const)

  2. Create a new secondary index to your table.

    • 'partition key': 'const_value'
    • 'sort key': the column what you want to filter
  3. You can use Query.

aws-dynamodb

Sign up to request clarification or add additional context in comments.

2 Comments

Yes i have already used DynamoDB Query in a way to make it work but the problem with that is every item getting inserted to my table has unique partition/sort key and that will not work because based on a filter criteria I have to get the results.
I like the idea but lets say that I create a GSI with its PK/HK as a constant and SK is a string and it could be only like apples or oranges will it work ? I am not sure if it will work because I agree that we can have 1 bucket/PK/HK as constant but the SK needs to be unqiue in that case isnt it ? Or do you think SK can repeat ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.