Well, as the title suggest I want to query on my DynamoDB table using GSI with the primary key and sort key (both from the GSI). I tried some ways to do it, but any success.
I have a table with the url-date-index, the url is the primary key from from the GSI, and the date is the sort key.
I tried the following:
Using
KeyConditionExpressionwith&comparator:This one retrieved me the error:
TypeError: expected string or bytes-like
boto3.resource('dynamodb').Table('table').query(
IndexName='url-date-index',
KeyConditionExpression=conditions.Key('url')).eq(url) & conditions.Key('date')).eq(date)
)
Using
KeyConditionExpressionandFilterExpression:This retrieved the following error:
Filter Expression can only contain non-primary key attributes
boto3.resource('dynamodb').Table('table').query(
IndexName='url-date-index',
KeyConditionExpression=conditions.Key('url')).eq(url),
FilterExpression=conditions.Key('date')).eq(date)
)
Using
ExpressionAttributeNames,ExpressionAttributeValuesandKeyConditionExpression:This returned anything, even not the item that matches the
urlanddateon the table.
boto3.resource('dynamodb').Table('table').query(
IndexName='url-date-index',
ExpressionAttributeNames={
'#n0': 'url',
'#n1': 'date'
},
ExpressionAttributeValues={
':v0': url,
':v1': date
},
KeyConditionExpression='(#n0 = :v0) AND (#n1 = :v1)'
)
Does anyone know what I'm doing wrong or what I can do to make this work.