I'm trying to download file that has many versions from version-enabled bucket. Using the bellow code, it always download the file that has latest version.
s3 = boto3.resource('s3')
bucket = s3.Bucket("mybucket")
bucket.download_file("somefile", "/donwload/path/somefile.txt")
How can I specify which version I want to download for the "somefile" file?
CodePudding user response:
As per the comments, Bucket.download_file
has an ExtraArgs
parameter, where you can specify additional parameters that are passed down to the Client.get_object
function that download_file
wraps. From the documentation of get_object
, you can see that the relevant argument is VersionId
.
s3 = boto3.resource('s3')
bucket = s3.Bucket("mybucket")
bucket.download_file(
"somefile",
"/donwload/path/somefile.txt",
ExtraArgs={"VersionId": "my_version"}
)