Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if DynamoDB table Empty

I have a dynamoDB table and I want to check if there are any items in it (using python). In other words, return true is the table is empty.

I am not sure how to go about this. Any suggestions?

like image 819
AdeEla Avatar asked May 10 '26 02:05

AdeEla


1 Answers

Using Scan

The best way is to scan and check the count. You might be using boto3 AWS sdk for python.Use the scan function to scan the whole table and get the count.This may not be costly as you are scanning the table only once and it would not scan the entire table. A single scan returns only 1 MB of data, so it would not be time consuming.

Read the docs for more details : Boto3 Docs

Using describe table

This could be helpful as well to get the count but

DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this value.

so this could be only used if you don't want the most recent updated value. Read the docs for more details : describe table dynamodb

like image 139
Rajan Sharma Avatar answered May 12 '26 15:05

Rajan Sharma