1
votes

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/

1
You mean using multiple secondary index on single query param?notionquest
yes @notionquestPAscalinox

1 Answers

4
votes

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)
)