'Amazon S3 object restore from GLACIER not working with Python boto3
Trying to restore an Amazon S3 object from GLACIER with the code below.
import boto3
s3 = boto3.resource('s3', verify=False)
bucket_name = r"my-source-bucket"
bucket = s3.Bucket(bucket_name)
key ="glacier_file2.txt"
try:
bucket.meta.client.restore_object(Bucket=bucket_name, Key=key, RestoreRequest={'Days': 1, 'GlacierJobParameters': {'Tier': 'Expedited'}})
except Exception as e:
print({"Problem Restoring": str(e)})
The code submits successfully, however the object still shows as in GLACIER in the AWS console as well as when I query it with boto3 even days later. If I run the following code I see it still shows GLACIER.
key = s3.Object(bucket_name,key)
print (key.storage_class)
print (key.restore)
>>>>GLACIER
>>>>ongoing-request="false", expiry-date="Sun, 19 Sep 2021 00:00:00 GMT"
When I try to do this same thing in the AWS console, I see that it says it's both in GLACIER AND restore is complete?
Does anyone have any insight? After restoring, I'm actually able to download the file, which tells me it's not actually in GLACIER, despite saying it is in the browser, and also in boto3. Is something wrong with how the storage class is being reported after a restore occurs?
edit I should point out I'm doing an expedited restore, which only takes a few minutes.
Solution 1:[1]
When restored, S3 will create a temporary copy of the object that is available to access for the specified duration. This is what you were seeing when you queried your request: it was finished (ongoing-request="false") and the requested duration was 1 day which is the expiry date (expiry-date="Sun, 19 Sep 2021 00:00:00 GMT").
https://aws.amazon.com/premiumsupport/knowledge-center/restore-s3-object-glacier-storage-class/
Solution 2:[2]
After doing a little more research, it appears that a "restore" is not what one would expect. Once an object goes to GLACIER there is no going back, other than "temporarily" restoring it (like I've done above) and then overwriting it. For example, I was able to run this command after restoring glacier_file2.txt
aws s3 cp s3://my-source-bucket/glacier_file2.txt s3://my-source-bucket/glacier_file2.txt --force-glacier-transfer --storage-class STANDARD
https://newbedev.com/how-do-i-restore-from-aws-glacier-back-to-s3-permanently
This would not work if I had not triggered the temporary GLACIER restore.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | franchyze923 |

