Hey,
When using the DynamoDB get_item function, an item is returned perfectly fine in a JSON format.
However, when using the batch_get_item function -
s = client.batch_get_item(
RequestItems={
'my_table':
{'Keys':
[
{'key':
{'S':'val1'}
},
{'key':
{'S':'val2'}
}
]
}
})
The response is returned as DynamoDB JSON -
u'Responses':
{u'my_table':
[
{u'key': {u'S': u'0.0'},
u'key2': {u'S': u'value'},
]
}
Is there a way to deal with this?
I couldn't find a way to parse responses like this in the boto docs, and when going through the code I see that responses for get_item are indeed parsed (transform.py), but nothing happens for batch_get_item
What's the solution? There has to be a better way than writing a parser from scrath...
Thanks!
I would just create a resource and then just drop down to the client. So something like this:
import boto3
dynamodb = boto3.resource('dynamodb')
s = dynamodb.meta.client.batch_get_item(
RequestItems={
'my_table':
{'Keys':
[
{'key':'val1'},
{'key':'val2'}
]
}
})
That should get it to you in non DynamoDB JSON format. Let us know if you have anymore questions.
Closing issue. Let us know if you have any follow up questions.
Hey @kyleknap
i used the above to read in batches, however it throws the following error
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the BatchGetItem operation: The provided key element does not match the schema
Table :
Primary partition key
queue (String)
Primary sort key
diff (Number)
code : response = table.meta.client.batch_get_item(
RequestItems = {
"TASK_SUMMARY":{
"Keys": [
{'queue':'UK_FRAUD'},
{'diff':10} ] }
},
)
Questions:
1) Where am i going wrong?
2) how can i pass multiple values for queues and diff
@kyleknap I have the same query working on client.batch_get_item returning the Dynamo JSON and on dynamodb.meta.client.batch_get_item returning empty results. Are you sure this is the right way on Boto3?
In the meantime, this helped: http://stackoverflow.com/questions/37872542/is-there-a-python-api-for-submitting-batch-get-requests-to-aws-dynamodb
boto3.dynamodb.types.TypeDeserializer
Most helpful comment
I would just create a resource and then just drop down to the client. So something like this:
That should get it to you in non DynamoDB JSON format. Let us know if you have anymore questions.