Boto3:有没有办法使用来自 dynamodb 的哈希范围键批量获取项目?

irr*_*lar 5 python boto boto3

我从他们的文档中看到您可以为单个项目 batch_get_item

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

但我不太确定如何从带有哈希范围键的表中获取项目。特别是批量获取仅具有哈希值的项目,这可能吗?

tah*_*ayk 3

你可以按照这个代码:

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"])
Run Code Online (Sandbox Code Playgroud)