Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto3: Table.get_item doesn't return items

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?

like image 897
Tsubasa Avatar asked Aug 01 '26 04:08

Tsubasa


1 Answers

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.

like image 185
Chris Williams Avatar answered Aug 02 '26 20:08

Chris Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!