I have more than 500,000 objects on s3. I am trying get the size of each object. I am using the following python code for that
import boto3
bucket = 'bucket'
prefix = 'prefix'
contents = boto3.client('s3').list_objects_v2(Bucket=bucket, MaxKeys=1000, Prefix=prefix)["Contents"]
for c in contents:
print(c["Size"])Run Code Online (Sandbox Code Playgroud)
But it just gave me the size of top 1000 objects. Based on the documentation we can't get more 1000. Is there any way I can get more than that?
boto3 和 dynamodb 分页器的文档指定在分页时应返回 NextToken,然后您将在下一个查询中包含该令牌以获取开始令牌以恢复分页会话(通过 RESTful API 访问信息时会发生这种情况)。
但是,我的测试表明它不会在结果中返回 NextToken,而是返回 LastEvaluatedKey。我想我可以使用 LastEvaluatedKey 作为令牌,但这不起作用?
paginator = client.get_paginator('scan')
page_iterator = paginator.paginate(TableName='test1', PaginationConfig={'PageSize': 1 , 'MaxItems': 5000, 'MaxSize': 1 })
for page in page_iterator:
print(page)
break
Run Code Online (Sandbox Code Playgroud)
我希望从 page_iterator 返回的页面对象包含 NextToken Key 但它没有?
{'Items': [{'PK': {'S': '99'}, 'SK': {'S': '99'}, 'data': {'S': 'Test Item 99'}}], 'Count': 1, 'ScannedCount': 1, 'LastEvaluatedKey': {'PK': {'S': '99'}, 'SK': {'S': '99'}}, 'ResponseMetadata': {'RequestId': 'DUE559L8KVKVH8H7G0G2JH0LUNVV4KQNSO5AEMVJF66Q9ASUAAJG', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'Server', 'date': 'Mon, 27 May 2019 14:22:09 GMT', 'content-type': 'application/x-amz-json-1.0', 'content-length': …Run Code Online (Sandbox Code Playgroud) 为了列出认知用户池的所有用户,我想到了使用 boto3 的client.list_users()- 功能,包括分页。
不过,如果我打电话print(client.can_paginate('list_users')),False返回,因为该功能list_users()是不分页。
是否有替代方法可以列出认知用户池的所有用户而不过滤那些已经被选中的用户?
我当前没有分页的代码如下所示:
client = boto3.client('cognito-idp',
region_name=aws_region,
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
config=config)
response = client.list_users(
UserPoolId=userpool_id,
AttributesToGet=[
'email','sub'
]
)
Run Code Online (Sandbox Code Playgroud)
提前谢谢了!