Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boto3: Is there a way to batch get items using hash range keys from dynamodb?

Tags:

python

boto3

boto

I see from their documentation you can batch_get_item for single items

http://boto3.readthedocs.io/en/latest/reference/services/dynamodb.html#DynamoDB.Client.batch_get_item

but I'm not quite sure how to get items from tables with hash range keys. Particularly batch getting items with just the hash value, is this possible?

like image 749
irregular Avatar asked Oct 29 '22 10:10

irregular


1 Answers

you can follow this code:

dynamodb = boto3.resource('dynamodb')
r = dynamodb.batch_get_item(RequestItems={
            'TABLE_NAME': {
                'Keys': [
                    {
                        'myPrimaryKey': "123",
                        'mySortKey': "65894"
                    },
                    {
                        'myPrimaryKey': "123",
                        'mySortKey': "65004"
                    },
                    {
                        'myPrimaryKey': "123",
                        'mySortKey': "69654"
                    }
                ],
            },
})

print(r["Responses"]["TABLE_NAME"])
print(r["UnprocessedKeys"])
like image 71
tahayk Avatar answered Nov 11 '22 22:11

tahayk