I was having already 7 items in the table and I inserted 8 items. Now My output has to show 15.
Still my out showing 7 which is old count. How to get the live updated count
From UI also when i check its showing 7 but when i checked live count by Start Scan, I got 15 entries
Is there time is there like some hours which will update the live count?
dynamo_resource = boto3.resource('dynamodb')
dynamodb_table_name = dynamo_resource.Table('details')
item_count_table = dynamodb_table_name.item_count
print('table_name count for field is', item_count_table)
using client
dynamoDBClient = boto3.client('dynamodb')
table = dynamoDBClient.describe_table(TableName='details')
print(table['Table']['ItemCount'])
In your example you are calling DynamoDB DescribeTable
which only updates its data approximately every 6 hours:
Item Count: 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.
In order to get the "Live Count" you have two possible options:
Option 1: Scan
the entire table.
dynamoDBClient = boto3.client('dynamodb')
item_count = dynamoDBClient.scan(TableName='details', Select='COUNT')
print(item_count)
Be aware this will call for a full table Scan
and may not be the best option for large tables.
Option 2: Update a counter for each item you write
You would need to use TransactWriteItems
and Update
a live counter for every Put
which you do to the table. This can be useful, but be aware that you will limit your throughput to 1000 WCU per second as you are focusing all your writes on a single item.
You can then return the live item count with a simple GetItem
.
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html