[英]AWS Lambda Python Boto3 - Item count dynamodb table
I am trying to count the total number of items in the Dynamobd table.我正在尝试计算 Dynamobd 表中的项目总数。 Boto3 documenation says item_count attribute.
Boto3 文档说 item_count 属性。 (integer) -- The number of items in the specified table.
(integer) -- 指定表中的项目数。 DynamoDB updates this value approximately every six hours.
DynamoDB 大约每六个小时更新一次此值。 Recent changes might not be reflected in this value.
最近的更改可能不会反映在此值中。
I populated about 100 records into that table.我在该表中填充了大约 100 条记录。 output shows 0 reccords
output 显示 0 条记录
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))
As you saw in the AWS documentation , item_count is:正如您在AWS 文档中看到的,item_count 是:
The number of items in the specified table.
指定表中的项目数。 DynamoDB updates this value approximately every six hours.
DynamoDB 大约每六个小时更新一次此值。 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
您最多需要等待 6 小时,平均 3 小时才能获得更新的商品数量
This is generally how large-scale distributed systems like S3 and DynamoDB work.这通常是 S3 和 DynamoDB 等大型分布式系统的工作方式。 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.
它们不会为您提供物体或物品的瞬时、准确计数,因为很难准确地保持该计数,并且在一般情况下瞬时计算的成本过高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.