I might be missing something, but I struggle to generate multiple sort keys dict for use with Boto3 Batch get Item in python.
For all other DB, which don't use sort key, I have something like this:
I have a method that queries dynamo, but I use helper that populates the keys node:
DYNAMODB_TABLE: {
'Keys': generate_keydicts(myids, table_name)
}
})
and:
if table_to_query == 'BossTable':
return [{'id': myid} for myid in myids]
And that works beautiful - as charm.
Now, this other table that is using sort key would need to have additional "json" object in the loop, something like:
if table_to_query == 'SortedKeyBossTable':
keys = []
for myid in myids:
single_key = {{'id': myid},{"sortkey":"sortkey1"},
{'id': myid},{"sortkey":"sortkey2"}}
keys.append(single_key)
return keys
But this is not a valid, hashable JSON - so it fails.
If I remove outside curly brackets - then it's a tuple - again fails.
I've tried to pass that manually, in code - and it worked, but I don't know how to generate this "json" that is not valid json, or object that is a list of objects.
I'm not even sure how is that called, and how can that be achieved.
Before anyone asks - I have 2k IDs that I need to check, out of 2 million entries, and - I guess I should have done regular query per ID, but since I have the code for batch item in place, and all post processing that I'm doing - I hoped it would be matter of adding one line.
I've also looked here: Is it possible to use multiple sort values in aws sdk dynamodb batchGetItem?
And some other places, but can't find a working example how to generate that object in python.