Skip to content

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

======================================================

			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})
Clone this wiki locally