Restore GLACIER Object to S3 Standard Tier

Viewed 2626

I'm working on a code that will restore objects from Glacier. The tier we will use is Standard. I'm following this doc:

Bot3 documentation on client.restor_object

See also this example from github account: https://github.com/boto/boto3/issues/380

This code is working without the Tier option in RestoreRequest.

 import boto3

s3 = boto3.resource('s3')
bucket = s3.Bucket('datasets-imported-imdb')
for obj_sum in bucket.objects.all():
    if obj_sum.key == 'testfile.mov':
        print(f'file being restored {obj_sum.key}')
        resp = bucket.meta.client.restore_object(
            Bucket=obj_sum.bucket_name,
            Key=obj_sum.key,
            RestoreRequest={'Days': 1,'Tier': 'Standard'}    
        )
    else:
        print(f'file not being restored {obj_sum.key}')

This is the traceback:

Traceback (most recent call last):
  File "test.py", line 8, in <module>
    resp = bucket.meta.client.restore_object(
  File "/home/alex_anadon/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/alex_anadon/.local/lib/python3.8/site-packages/botocore/client.py", line 676, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (MalformedXML) when calling the RestoreObject operation: The XML you provided was not well-formed or did not validate against our published schema
1 Answers

The documentation shows:

response = client.restore_object(
    Bucket='string',
    Key='string',
    VersionId='string',
    RestoreRequest={
        'Days': 123,
        'GlacierJobParameters': {
            'Tier': 'Standard'|'Bulk'|'Expedited'
        },
    ...

Therefore, you should use:

        resp = bucket.meta.client.restore_object(
            Bucket=obj_sum.bucket_name,
            Key=obj_sum.key,
            RestoreRequest={'Days': 1, 'GlacierJobParameters': {'Tier': 'Standard'}}
        )
Related