S3.Client.
list_object_versions
(**kwargs)¶Returns metadata about all versions of the objects in a bucket. You can also use request parameters as selection criteria to return metadata about a subset of all the object versions.
Warning
To use this operation, you must have permissions to perform the s3:ListBucketVersions
action. Be aware of the name difference.
Note
A 200 OK response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately.
To use this operation, you must have READ access to the bucket.
This action is not supported by Amazon S3 on Outposts.
The following operations are related to ListObjectVersions
:
See also: AWS API Documentation
Request Syntax
response = client.list_object_versions(
Bucket='string',
Delimiter='string',
EncodingType='url',
KeyMarker='string',
MaxKeys=123,
Prefix='string',
VersionIdMarker='string',
ExpectedBucketOwner='string'
)
[REQUIRED]
The bucket name that contains the objects.
prefix
and the first occurrence of the delimiter are grouped under a single result element in CommonPrefixes. These groups are counted as one result against the max-keys limitation. These keys are not returned elsewhere in the response.403 Forbidden
(access denied).dict
Response Syntax
{
'IsTruncated': True|False,
'KeyMarker': 'string',
'VersionIdMarker': 'string',
'NextKeyMarker': 'string',
'NextVersionIdMarker': 'string',
'Versions': [
{
'ETag': 'string',
'ChecksumAlgorithm': [
'CRC32'|'CRC32C'|'SHA1'|'SHA256',
],
'Size': 123,
'StorageClass': 'STANDARD',
'Key': 'string',
'VersionId': 'string',
'IsLatest': True|False,
'LastModified': datetime(2015, 1, 1),
'Owner': {
'DisplayName': 'string',
'ID': 'string'
}
},
],
'DeleteMarkers': [
{
'Owner': {
'DisplayName': 'string',
'ID': 'string'
},
'Key': 'string',
'VersionId': 'string',
'IsLatest': True|False,
'LastModified': datetime(2015, 1, 1)
},
],
'Name': 'string',
'Prefix': 'string',
'Delimiter': 'string',
'MaxKeys': 123,
'CommonPrefixes': [
{
'Prefix': 'string'
},
],
'EncodingType': 'url'
}
Response Structure
(dict) --
IsTruncated (boolean) --
A flag that indicates whether Amazon S3 returned all of the results that satisfied the search criteria. If your results were truncated, you can make a follow-up paginated request using the NextKeyMarker and NextVersionIdMarker response parameters as a starting place in another request to return the rest of the results.
KeyMarker (string) --
Marks the last key returned in a truncated response.
VersionIdMarker (string) --
Marks the last version of the key returned in a truncated response.
NextKeyMarker (string) --
When the number of responses exceeds the value of MaxKeys
, NextKeyMarker
specifies the first key not returned that satisfies the search criteria. Use this value for the key-marker request parameter in a subsequent request.
NextVersionIdMarker (string) --
When the number of responses exceeds the value of MaxKeys
, NextVersionIdMarker
specifies the first object version not returned that satisfies the search criteria. Use this value for the version-id-marker request parameter in a subsequent request.
Versions (list) --
Container for version information.
(dict) --
The version of an object.
ETag (string) --
The entity tag is an MD5 hash of that version of the object.
ChecksumAlgorithm (list) --
The algorithm that was used to create a checksum of the object.
Size (integer) --
Size in bytes of the object.
StorageClass (string) --
The class of storage used to store the object.
Key (string) --
The object key.
VersionId (string) --
Version ID of an object.
IsLatest (boolean) --
Specifies whether the object is (true) or is not (false) the latest version of an object.
LastModified (datetime) --
Date and time the object was last modified.
Owner (dict) --
Specifies the owner of the object.
DisplayName (string) --
Container for the display name of the owner.
ID (string) --
Container for the ID of the owner.
DeleteMarkers (list) --
Container for an object that is a delete marker.
(dict) --
Information about the delete marker.
Owner (dict) --
The account that created the delete marker.>
DisplayName (string) --
Container for the display name of the owner.
ID (string) --
Container for the ID of the owner.
Key (string) --
The object key.
VersionId (string) --
Version ID of an object.
IsLatest (boolean) --
Specifies whether the object is (true) or is not (false) the latest version of an object.
LastModified (datetime) --
Date and time the object was last modified.
Name (string) --
The bucket name.
Prefix (string) --
Selects objects that start with the value supplied by this parameter.
Delimiter (string) --
The delimiter grouping the included keys. A delimiter is a character that you specify to group keys. All keys that contain the same string between the prefix and the first occurrence of the delimiter are grouped under a single result element in CommonPrefixes
. These groups are counted as one result against the max-keys limitation. These keys are not returned elsewhere in the response.
MaxKeys (integer) --
Specifies the maximum number of objects to return.
CommonPrefixes (list) --
All of the keys rolled up into a common prefix count as a single return when calculating the number of returns.
(dict) --
Container for all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter. CommonPrefixes lists keys that act like subdirectories in the directory specified by Prefix. For example, if the prefix is notes/ and the delimiter is a slash (/) as in notes/summer/july, the common prefix is notes/summer/.
Prefix (string) --
Container for the specified common prefix.
EncodingType (string) --
Encoding type used by Amazon S3 to encode object key names in the XML response.
If you specify encoding-type request parameter, Amazon S3 includes this element in the response, and returns encoded key name values in the following response elements:
KeyMarker, NextKeyMarker, Prefix, Key
, andDelimiter
.
Examples
The following example return versions of an object with specific key name prefix. The request limits the number of items returned to two. If there are are more than two object version, S3 returns NextToken in the response. You can specify this token value in your next request to fetch next set of object versions.
response = client.list_object_versions(
Bucket='examplebucket',
Prefix='HappyFace.jpg',
)
print(response)
Expected Output:
{
'Versions': [
{
'ETag': '"6805f2cfc46c0f04559748bb039d69ae"',
'IsLatest': True,
'Key': 'HappyFace.jpg',
'LastModified': datetime(2016, 12, 15, 1, 19, 41, 3, 350, 0),
'Owner': {
'DisplayName': 'owner-display-name',
'ID': 'examplee7a2f25102679df27bb0ae12b3f85be6f290b936c4393484be31bebcc',
},
'Size': 3191,
'StorageClass': 'STANDARD',
'VersionId': 'null',
},
{
'ETag': '"6805f2cfc46c0f04559748bb039d69ae"',
'IsLatest': False,
'Key': 'HappyFace.jpg',
'LastModified': datetime(2016, 12, 13, 0, 58, 26, 1, 348, 0),
'Owner': {
'DisplayName': 'owner-display-name',
'ID': 'examplee7a2f25102679df27bb0ae12b3f85be6f290b936c4393484be31bebcc',
},
'Size': 3191,
'StorageClass': 'STANDARD',
'VersionId': 'PHtexPGjH2y.zBgT8LmB7wwLI2mpbz.k',
},
],
'ResponseMetadata': {
'...': '...',
},
}