skip to Main Content

I recently have restored S3 Deep Archive objects using Python.

There are over a million of them and I need to make it sure clearly.

If possible, I would like to use python to check if all objects have been restored.

Can someone please advice me how to do this?

Thank you

2

Answers


  1. From restore_object() documentation:

    To get the status of object restoration, you can send a HEAD request. Operations return the x-amz-restore header, which provides information about the restoration status, in the response.

    And under head_object():

    If an archive copy is already restored, the header value indicates when Amazon S3 is scheduled to delete the object copy. For example:

    x-amz-restore: ongoing-request="false", expiry-date="Fri, 21 Dec 2012 00:00:00 GMT"

    Login or Signup to reply.
  2. Although not Python, here is the logic to perform this use case using AWS SDK for Java v2.

    package com.example.s3;
    
    import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.s3.S3Client;
    import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
    import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
    import software.amazon.awssdk.services.s3.model.S3Exception;
    
    public class GetObjectRestoreStatus {
        public static void main(String[] args) {
            final String usage = "n" +
                "Usage:n" +
                "    <bucketName> <keyName> nn" +
                "Where:n" +
                "    bucketName - The Amazon S3 bucket name. nn"+
                "    keyName - A key name that represents the object. nn";
    
            if (args.length != 2) {
                System.out.println(usage);
                System.exit(1);
            }
    
            String bucketName = args[0];
            String keyName = args[1];
            ProfileCredentialsProvider credentialsProvider = ProfileCredentialsProvider.create();
            Region region = Region.US_EAST_1;
            S3Client s3 = S3Client.builder()
                .region(region)
                .credentialsProvider(credentialsProvider)
                .build();
    
            checkStatus(s3,bucketName,keyName);
            s3.close();
        }
    
        // snippet-start:[s3.java2.getrestorestatus.main]
        public static void checkStatus(S3Client s3, String bucketName, String keyName) {
            try {
                HeadObjectRequest headObjectRequest = HeadObjectRequest.builder()
                    .bucket(bucketName)
                    .key(keyName)
                    .build();
    
                HeadObjectResponse response =  s3.headObject(headObjectRequest);
                System.out.println("The Amazon S3 object restoration status is "+response.restore());
    
            } catch (S3Exception e) {
                System.err.println(e.awsErrorDetails().errorMessage());
                System.exit(1);
            }
        }
        // snippet-end:[s3.java2.getrestorestatus.main]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search