kxx*_*ing 14 python boto amazon-dynamodb
我正在使用boto.dynamodb2,似乎我可以使用Table.query_count().但是,在未应用查询过滤器时,它引发了异常.
我该怎么做才能解决这个问题?
BTW,boto.dynamodb2.table.Table.Query可以使用的过滤器文件在哪里?我试着搜索但没有发现任何东西.
Jar*_*eld 16
有两种方法可以在DynamoDB中获取行数.
第一种是执行全表扫描并随时计算行数.对于任何合理大小的表,这通常是一个可怕的想法,因为它将消耗所有配置的读取吞吐量.
另一种方法是使用Describe Table请求来估计表中的行数.这将立即返回,但只会根据AWS文档定期更新.
指定索引中的项目数.DynamoDB大约每六个小时更新一次该值.最近的更改可能不会反映在此值中.
根据文档boto3
“指定表中的项目数。DynamoDB大约每六个小时更新一次该值。最近的更改可能不会反映在该值中。”
import boto3
dynamoDBResource = boto3.resource('dynamodb')
table = dynamoDBResource.Table('tableName')
print(table.item_count)
Run Code Online (Sandbox Code Playgroud)
或者您可以使用DescribeTable:
import boto3
dynamoDBClient = boto3.client('dynamodb')
table = dynamoDBClient.describe_table(
TableName='tableName'
)
print(table)
Run Code Online (Sandbox Code Playgroud)
如果要计算物品的数量:
import boto3
client = boto3.client('dynamodb','us-east-1')
response = client.describe_table(TableName='test')
print(response['Table']['ItemCount'])
#ItemCount (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.
Run Code Online (Sandbox Code Playgroud)
参考:Boto3文档(在 describe_table() 中的 ItemCount 下)
| 归档时间: |
|
| 查看次数: |
18699 次 |
| 最近记录: |