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

Last updated: 2019-05-30

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.

$ 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 is 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 must transition the object back to the Amazon S3 Standard storage class by that date.

Transition the object back to the Amazon S3 Standard storage class

To transition the object back to the Amazon S3 Standard storage class, 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