LoGan
LoGan

Reputation: 115

How to retrieve all the item from DynamoDB using boto3?

I want to retrieve all the items from my table without specifying any particular parameter, I can do it using Key Pair, but want to get all items. How to do it?

import boto3

dynamodb = boto3.resource('dynamodb')

table = dynamodb.Table('Email')

response = table.get_item(
    Key={
        "id": "2"
    }
)
item = response['Item']
print(item)

This way I can do, but how to retrieve all items? is there any method?

Upvotes: 2

Views: 6159

Answers (1)

Chris Williams
Chris Williams

Reputation: 35258

If you want to retrieve all items you will need to use the Scan command.

You can do this by running

response = table.scan()

Be aware that running this will utilise a large number of read credits (RCU). If you're using eventual consistency 1 RCU will be equal to 2 items (under 4KB) and strongly consistent will be 1 item per each RCU (under 4KB).

Here is the consideration page for scans vs queries in AWS documentation.

Upvotes: 2

Related Questions