简体   繁体   English

AWS Lambda Python Boto3 - 项目计数 dynamodb 表

[英]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.

相关问题 AWS Lambda Boto3 python - dynamodb 表上的过滤器表达式抛出错误“errorMessage”:“名称'Attr'未定义”, - AWS Lambda Boto3 python - filter expression on dynamodb table throw error "errorMessage": "name 'Attr' is not defined", 无法解析 AWS DynamoDB 二进制获取 boto3 python 中的项目 - Unable to parse AWS DynamoDB binary get item in boto3 python Python Boto3 AWS DynamoDB从表中获取项目而无排序键 - Python Boto3 AWS DynamoDB get item from table without sort key 如何使用 boto3(lambda) 对 AWS dynamodb 表进行分组并获取分区键的最新值? - how to group AWS dynamodb table and get latest value of partition key using boto3(lambda)? Python Boto3 AWS Lambda TypeDeserializer - 错误:TypeError:Dynamodb 类型<name>不支持</name> - Python Boto3 AWS Lambda TypeDeserializer - Error: TypeError: Dynamodb type <name> is not supported 测试 Python AWS Lambda boto3 初始化 - Testing Python AWS Lambda boto3 initialization 如何使用Python boto3从AWS DynamoDB表中获取特定属性的所有项目? - How to fetch all items of a particular Attribute from an AWS DynamoDB Table using Python boto3? AWS DynamoDB Python - 无法识别boto3 Key()方法(查询) - AWS DynamoDB Python - boto3 Key() methods not recognized (Query) AWS DynamoDB 使用 Python/Boto3/Lamba 更新整数计数器 - AWS DynamoDB update integer counter with Python/Boto3/Lamba 将 AWS DynamoDB 数据转换为 Python/Boto3/Lamba 中的 json 格式 - AWS DynamoDB data to json format in Python/Boto3/Lamba
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM