How can use the AWS CLI to restore an Amazon S3 object from the S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive storage class?

5 minute read
1

I archived an Amazon Simple Storage Service (Amazon S3) object to the Amazon S3 Glacier Flexible Retrieval or Amazon S3 Glacier Deep Archive storage class. I want to restore the object with the AWS Command Line Interface (AWS CLI).

Resolution

Note: If you receive errors when running AWS CLI commands, make sure that you're using the most recent AWS CLI version.

Initiate a restore request

To initiate a restore request, run the following command. Replace all the values in the example command with the values for your bucket, object, and restore request.

Note: Because data retrieval charges are based on the quantity of requests, confirm that the parameters of your restore request are correct.

$ aws s3api restore-object --bucket awsexamplebucket --key dir1/example.obj --restore-request '{"Days":25,"GlacierJobParameters":{"Tier":"Standard"}}'

The retrieval request creates a temporary copy of your data in the S3 Standard storage class and leaves the archived data intact. In this example, it creates the copy for 25 days. In AWS Regions where Reduced Redundancy Storage is a lower price than S3 Standard, temporarily available data is billed as Reduced Redundancy Storage. However, the Reduced Redundancy billing storage class doesn't reflect how the data is stored.

Note the following modifications that you can make to the command:

  • To restore a specific object version in a versioned bucket, include the --version-id option, and then specify the corresponding version ID.
  • For the S3 Glacier Flexible Retrieval storage class, you can use the Expedited, Standard, or Bulk retrieval options. However, you can use only the Standard or Bulk retrieval options for the S3 Glacier Deep Archive storage class.
  • If the JSON syntax in the example results in an error on a Windows client, then replace the restore request with the following syntax:
--restore-request Days=25,GlacierJobParameters={"Tier"="Standard"}

Note: For objects that are stored in S3 Glacier Instant Retrieval, the data retrieval is instant and you don't need to use the restore operation. For more information, see Amazon S3 storage classes.

Monitor the status of your restore request

To monitor the status of your restore request, run the following command:

aws s3api head-object --bucket awsexamplebucket --key dir1/example.obj

If the restore is still in progress after you run the command, then you receive a response similar to the following message:

{  
    "Restore": "ongoing-request=\"true\"",  
    ...  
    "StorageClass": "GLACIER | DEEP_ARCHIVE",  
    "Metadata": {}  
}

After the restore is complete, you receive a response similar to the following message:

{  
    "Restore": "ongoing-request=\"false\", expiry-date=\"Sun, 13 Aug 2017 00:00:00 GMT\"",  
    ...  
    "StorageClass": "GLACIER | DEEP_ARCHIVE",  
    "Metadata": {}  
}

Note the expiry-date in the response. You have until this time to access the temporary store object that's stored in the S3 Standard storage class. The temporary object is available with the archived object that's in the S3 Glacier Flexible Retrieval or S3 Glacier Deep Archive storage class. After the expiry-date elapses, Amazon S3 removes the temporary object. You must change the object's storage class before the temporary object expires. To change the object's storage class after the expiry-date, initiate a new restore request.

Change the object's storage class to Amazon S3 Standard

To change the object's storage class to Amazon S3 Standard, use copy. You can overwrite the existing object or copy the object into another location.

Warning: If you're using version 1.x of the AWS CLI, then verify that the multipart threshold is set to 5 GB before you copy an object. Otherwise, when the object size is larger than the multipart thresholds of the AWS CLI, you lose the object's user metadata. To preserve user metadata for objects larger than 5 GB, use version 2.x of the AWS CLI.

(Optional) To increase the multipart threshold of the AWS CLI, run the following command:

aws configure set default.s3.multipart_threshold 5GB

To overwrite the existing object with the Amazon S3 Standard storage class, run the following command:

aws s3 cp s3://awsexamplebucket/dir1/example.obj s3://awsexamplebucket/dir1/example.obj --storage-class STANDARD

To perform a recursive copy for an entire prefix and overwrite existing objects with the Amazon S3 Standard storage class, run the following command:

aws s3 cp s3://awsexamplebucket/dir1/ s3://awsexamplebucket/dir1/ --storage-class STANDARD --recursive --force-glacier-transfer

Note: Objects that are archived to S3 Glacier Flexible Retrieval have a minimum storage duration of 90 days. Objects that are archived to S3 Glacier Deep Archive have a minimum storage duration of 180 days. If you overwrite an object in S3 Glacier Flexible Retrieval before the 90-day minimum, then you're charged for 90 days. Similarly, for objects that you overwrite in the S3 Glacier Deep Archive before the 180-day minimum, you're charged for 180 days.

To copy the object into another location, run the following command:

aws s3 cp s3://awsexamplebucket/dir1/example.obj s3://awsexamplebucket/dir2/example2.obj

Note: For suspended buckets or buckets with versioning turned on, this step creates additional copies of objects. These additional objects also incur storage costs. To avoid storage costs, remove the non-current versions that are still in the Amazon S3 Glacier storage class. Or, create an S3 Lifecycle expiration rule.

Related information

How can I initiate restores for a large volume of Amazon S3 objects that are currently in the S3 Glacier or S3 Glacier Deep Archive storage class?

How do I use the restore tiers in the Amazon S3 console to restore archived objects from Amazon S3 Glacier storage class?

Restoring an archived object

AWS OFFICIAL
AWS OFFICIALUpdated 10 months ago