Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AWS Lambda Python Boto3 – Item count dynamodb table

I am trying to count the total number of items in the Dynamobd table. Boto3 documenation says
item_count attribute.
(integer) —
The number of items in the specified table. DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this value.

I populated about 100 records into that table. output shows 0 reccords

 import json
 import os
 import boto3
 from pprint import pprint

 tableName = os.environ.get('TABLE')
 fieldName = os.environ.get('FIELD')

 dbclient = boto3.resource('dynamodb')

 def lambda_handler(event, context):               
            tableresource = dbclient.Table(tableName)        
            count = tableresource.item_count
            print('total items in the table are ' + str(count))
 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As you saw in the AWS documentation, item_count is:

The number of items in the specified table. DynamoDB updates this value approximately every six hours. Recent changes might not be reflected in this value.

It looks like you added the new items very recently so that count will not be accurate right now. You would have to wait for 6 hours max, 3 hours on average to get an updated item count

This is generally how large-scale distributed systems like S3 and DynamoDB work. They don’t offer you an instantaneous, accurate count of objects or items because it’s difficult to maintain that count accurately and the cost to calculate it instantaneously is prohibitive in the general case.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading