Home > Mobile >  Retrieve deleted AWS S3 file by version
Retrieve deleted AWS S3 file by version

Time:10-10

I am trying to retrieve a deleted file from s3, without restoring it. I can do it through the console (clicking Download), but I need to do it programmatically.

The following call lists the version I need:

s3.list_object_versions(
    Bucket="...", 
    KeyMarker="/.../part-00000-5ceb032b-c918-47df-a2ad-f02f3790077a-c000.csv", 
    VersionIdMarker = "A1GxocexjsirkzKfo47lvQ0r7ythwCWM",
    MaxKeys=1
)

However, s3.get_object() with the same parameters, returns "ClientError: An error occurred (NoSuchVersion) when calling the GetObject operation: The specified version does not exist."

What is the proper way of retrieving a specific version of a deleted file?

CodePudding user response:

Based on the comments. The issue was caused by using / in a key a prefix. Prefixes do not start with a /. Thus it should be:

KeyMarker=".../part-00000-5ceb032b-c918-47df-a2ad-f02f3790077a-c000.csv"
  • Related