Restore file from deep archive S3 Glacier and Lambda
Vaquar Khan edited this page Dec 11, 2022
·
3 revisions
Note : Expedited retrievals are typically made available within 1 โ 5 minutes. Standard retrievals complete within 3 โ 5 hours. Bulk retrievals complete within 5 โ 12 hours.
#Restore back to S3
aws s3api restore-object --bucket bucketname --key path/to/object.zip --restore-request '{"Days":25,"GlacierJobParameters":
{"Tier":"Standard"}}'
#Read file from S3
aws s3api head-object --bucket bucketname --key path/to/object.zip
#Copy to your local
aws s3 cp s3://bucketnamepath/to/object.zip object.zip
-
https://aws.amazon.com/premiumsupport/knowledge-center/restore-s3-object-glacier-storage-class/
aws s3 ls s3://<BUCKET_NAME> --recursive | awk '{print $4}' | xargs -L 1 aws s3api restore-object --restore-request '{"Days": <DAYS>,"GlacierJobParameters":{"Tier":"<TIER>"}}' --bucket <BUCKET_NAME> --key
======================================================
import boto3
def lambda_handler(event, context):
s3 = boto3.resource('s3')
bucket = s3.Bucket('your-bucket')
for obj_sum in bucket.objects.all():
obj = s3.Object(obj_sum.bucket_name, obj_sum.key)
if obj.storage_class == 'GLACIER':
# Try to restore the object if the storage class is glacier and
# the object does not have a completed or ongoing restoration
# request.
if obj.restore is None:
print('Submitting restoration request: %s' % obj.key)
obj.restore_object(RestoreRequest={'Days': 10})
# Print out objects whose restoration is on-going
elif 'ongoing-request โ="true"' in obj.restore:
print('Restoration in-progress: %s' % obj.key)
# Print out objects whose restoration is complete
elif 'ongoing-request โ="false"' in obj.restore:
print('Restoration complete: %s' % obj.key)
One restore done run 2nd lambda
import boto3
s3 = boto3.resource('s3')
def lambda_handler(event, context):
# source bucket
bucket = s3.Bucket('source-bucket')
# destination bucket
dest_bucket = s3.Bucket('destination-bucket')
print(bucket)
print(dest_bucket)
for obj in bucket.objects.all():
dest_key = obj.key
print(dest_key)
s3.Object(dest_bucket.name, dest_key).copy_from(CopySource = {'Bucket':
obj.bucket_name, 'Key': obj.key})
-
https://www.infinityworks.com/insights/restoring-2-million-objects-from-glacier/
aws glacier initiate-job --account-id XXXXXXXXXXXXXXXX --vault-name XXX-vault --job-parameters "{ \"Type\": \"inventory- retrieval\" }" { "location": "/XXXXXX/vaults/xxx-vault/jobs/YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY", "jobId": "TYTYTYTYTYTYTTYTYTYTYTYTYTYTYTYTYYYYTTTY1" }
-
https://www.alterio.us/post/unknown-options-inventory-retrieval