To get the object versions of a single object in AWS S3, we will need to use the
list_object_versions() method of boto3. Below are 3 methods to list all the versions of a single S3 object using Python and boto3.
- Example 1: Code to list all versions of an S3 object file using boto3 resource
- Example 2: Code to list all versions of an S3 object file using boto3 client paginator
- Example 3: Code to list all versions of an S3 object file using boto3 client Next Marker
You can scroll to the codes below to quickly access the Python scripts.
All 3 codes do the same thing. The function
get_file_versions_list() will accept the bucket name (
bucket_name) and the target S3 object key (
object_key), then it will use boto3 to get the list of object versions and delete markers of the target S3 object. It will then sort that list from latest to oldest, and then count the number of versions the object has.
- Example Codes
- Working with Prefix Parameter
- Working with Delete Markers
- Sorting the Response
Getting the list of versions and the delete markers was not as straight as I thought it would be. In the latter part of this article, I will be discussing the complexity of the prefix parameter and the delete markers.Continue reading How to get all versions of a single object file in an AWS S3 Bucket using Python boto3