2

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?

LoGan
  • 97
  • 4
  • 13

1 Answers1

1

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.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • 2
    Also be aware there is an overall size limit in what is brought back. A SCAN request can be max 1MB. If the scan results is, for example, 5MB of data in total, you will need to use pagination to get get the next 1MB, and the next and so on. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.Pagination – NoSQLKnowHow Jul 05 '20 at 01:45