0

I am new to dynamoDb and exploring its docs these days. I read about secondary index in dynamodb and have a small confusion. When we create a secondary index we specify partition and sort key (optional) for that index but do we also add attributes to secondary index which which we'll be querying using the secondary index?

Let's say, I have a table named Person and it contain attributes such as Name, Age, Gender, Contact, Star. It has name as the partition key and now I want to create a secondary index on Age such that I can query using Age and get the attributes - contact, star, name. Should I add these attributes (contact, star, name) to secondary index as well while creating it or I can just need to specify partition key (age in this case)?

1 Answer 1

0

You are only required to define the partition key Age in this case. By default, the projection will include ALL which means it will replicate the entire base table item (contact, star, name) into the index.

You can optionally choose to project only a subset of the attributes, (contact, star), for example.

The base table keys will always be projected, no matter if you exclude them from the Incudes projection type, no Name will always exist in the index at minimum.

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Projection.html

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

Comments

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.