DynamoDB local GSI KeyConditionExpression difference from live Dynamo


I'm running some tests with dynamodb local and live dynamo. When I use a KeyConditionExpression, only the hash key is allowed with live dynamo and to filter results based on the sort key I have to use a FilterExpression. In dynamodb local, the opposite is true. I want my code to be the same for my local tests and in production, but it doesn't seem possible with this difference. Here's some example code:

table = boto3.resource('dynamodb').Table('tablename')  
# Table has hash/sort keys of `hash` and `sort`  
# GSI of table has hash/sort keys of `gsihash` and `sort`  
# Works with dynamodb local, throws an error with live dynamo  
table.query(KeyConditionExpression=Key('hash').eq('somevalue') & Key('sort').begins_with('someprefix'), IndexName='GSI')  
# Works with live dynamo, throws an error with dynamodb local  
table.query(KeyConditionExpression=Key('hash').eq('somevalue'), FilterExpression=Attr('sort').begins_with('someprefix'), IndexName='GSI')  

Edited by: ewok on Dec 29, 2020 7:30 AM

Edited by: ewok on Dec 29, 2020 8:33 AM

Nevermind, was a difference in the table definition locally vs live

asked 4 years ago393 views
1 Answer

See edit

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions