How can I restore an S3 object from the Amazon Glacier storage class using the AWS CLI?

Last updated: 2020-03-27

I archived an Amazon Simple Storage Service (Amazon S3) object to the Amazon Simple Storage Service Glacier storage class by using a lifecycle configuration. How do I restore the object using the AWS Command Line Interface (AWS CLI)?

Resolution

Follow these steps to restore an S3 object from the Amazon S3 Glacier storage class using the AWS CLI:

Initiate a restore request

Run the following command to initiate a restore request. Be sure to 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, be sure to 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"}}'

After you run this command, a temporary copy of the object is made available for the duration specified in the restore request, such as the 25 days used in this example.

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.
  • If the JSON syntax used in the example results in an error on a Windows client, replace the restore request with the following syntax:
--restore-request Days=25,GlacierJobParameters={"Tier"="Standard"}

Monitor the status of your restore request

Run the following command to monitor the status of your restore request:

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

After you run the command, and if the restore is still in progress, you receive a response similar to the following:

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

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

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

Note the expiry-date in the response—you have until this time to access the temporary store object (stored in the Reduced Redundancy storage class). The temporary object is made available alongside the archived object that's in the S3 Glacier storage class. After the expiry-date elapses, the temporary object is removed. You must change the object's storage class before the temporary object expires. To change the object's storage class after the expiry-date, you must 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, run a copy operation either by overwriting the existing object or copying the object into another location.

To overwrite the existing object with the Amazon S3 Standard storage class, run this 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 this command: 

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

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

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