import boto3
# Create an S3 client
s3 = boto3.client('s3')
# Specify the bucket name
bucket_name = 'your_bucket_name'
# List all versions of objects in the bucket
object_versions = s3.list_object_versions(Bucket=bucket_name)
# Print information about each version (including delete markers)
for version in object_versions.get('Versions', []):
print(f"Key: {version['Key']}, VersionId: {version['VersionId']}, IsDeleteMarker: False")
# Print information about each delete marker (if any)
for delete_marker in object_versions.get('DeleteMarkers', []):
print(f"Key: {delete_marker['Key']}, VersionId: {delete_marker['VersionId']}, IsDeleteMarker: True")
2条答案
按热度按时间5q4ezhmt1#
我发现了问题。boto 3的列表对象API只列出了有限的结果(~1000个对象)。要超出此范围,您可能需要使用paginator。
下面是一个示例代码,你可以忽略不需要的行。
字符串
ssgvzors2#
字符串
此代码将打印所有版本的信息,包括版本化对象及其删除标记。