I execute this code in my local machine.
import boto3
boto3.resource('dynamodb').Table('table_name').get_item(Key={'id': 'id'})
And it returns this.
{'ResponseMetadata': {'RequestId': 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
'HTTPStatusCode': 200,
'HTTPHeaders': {'server': 'Server',
'date': 'Sat, 29 Aug 2020 08:23:07 GMT',
'content-type': 'application/x-amz-json-1.0',
'content-length': '2',
'connection': 'keep-alive',
'x-amzn-requestid': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'x-amz-crc32': 'xxxxxxxxxxxxxxxxxx'},
'RetryAttempts': 0}}
How can I get an item from dynamodb with boto3?
The expected response of GetItem should look like the below syntax.
{
'Item': {
'AlbumTitle': {
'S': 'Songs About Life',
},
'Artist': {
'S': 'Acme Band',
},
'SongTitle': {
'S': 'Happy Day',
},
},
'ResponseMetadata': {
'...': '...',
},
}
As you have ResponseMetadata and it returned a 200 this indicates that the request to DynamoDB was indeed successful but that no item with key id had a value of id.
You should validate that the value being passed in is a real ID value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With