想知道下面 AWS CLI 的 python boto3 代码
aws s3api list-objects-v2 \
--bucket myBucket \
--prefix path1/path2 \
--query 'reverse(sort_by(Contents,&LastModified))[0]'
我没有看到 list_objects_v2 的任何查询选项
https://boto3.readthedocs.io/en/stable/reference/services/s3.html#S3.Client.list_objects_v2 https://boto3.readthedocs.io/en/stable/reference/services/s3.html#S3.Client.list_objects_v2
The --query
能力在AWS 命令行界面 (CLI) http://aws.amazon.com/cli/是 CLI 本身的一项功能,而不是在 API 调用期间执行。
如果您使用的是 boto3list_object_v2() command http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.list_objects_v2,返回完整的结果集。
那么你可以使用Python来操作结果.
您似乎想要列出存储桶/路径中的最新对象,因此您可以使用类似以下内容的内容:
import boto3
client = boto3.client('s3',region_name='ap-southeast-2')
response = client.list_objects_v2(Bucket='my-bucket')
print (sorted(response['Contents'], key=lambda item: item['LastModified'])[-1])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)