1

I'm looking to request my DynamoDB table using to secondary-index I've made in my query.

As of now for a single secondary-index I'm doing :

response = dynamodb.Table('TABLE').query(
    IndexName='permaname-index',
    KeyConditionExpression=Key('permaname').eq(permaname)
)

I would build my KeyConditionExpression like this :

KeyConditionExpression=Key('permaname').eq(permaname) & Key('source').eq(source)

I've read again and again this doc but I can not figure out how to do:

https://docs.aws.amazon.com/fr_fr/amazondynamodb/latest/gettingstartedguide/GettingStarted.Python.04.html

and

https://boto3.readthedocs.io/en/latest/

2
  • You mean using multiple secondary index on single query param? Commented Aug 14, 2017 at 11:11
  • yes @notionquest Commented Aug 14, 2017 at 11:12

1 Answer 1

6

The DynamoDB Query (i.e. Query API params) can get data from single resource at a time (i.e. a table or GSI). In other words, you can't retrieve data from multiple tables or GSI in a single Query param. DynamoDB Query can refer to only one resource at a time.

Unlike, RDBMS which can refer to multiple tables, DynamoDB can't refer to multiple tables or GSI at a same time (i.e. in a single Query).

Because of this reason, DynamoDB has a feature to include all the attributes in main table in GSI. You can use ProjectionType to include all the attributes in a table onto GSI while creating the GSI for the table.

ProjectionType: ALL

Sample GSI query:-

response = table.query(
    IndexName='Movies_Gsi',
    KeyConditionExpression=Key('title').eq('Movie with nested map') & Key('yearkey').eq(2017)
)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your answer but I'm not sur to understand how to build my request. Could you please show me an exemple using my case @notionquest ?
Both are key attributes
I have updated the sample GSI query which works fine for me. If something is not working for you, please add the error message on OP.

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.