Amazon S3 – How to PUT Files Directly to Glacier

amazon s3amazon-glacieraws-cli

This AWS post from 2018 makes it sound like it should be possible to make S3 style PUT requests to create archives in glacier now:

I'm interpreting that to mean that you could use the s3 CLI or sdk interactions for uploading files, rather than the glacier specific api, or transitioning files. Is this correct?

I can't find any documentation on how this would actually work, as the link about S3 PUT to Glacier just goes to a list of storage classes. Tried experimenting some with aws s3 cp, but I'm not clear on what you would use for the bucket/s3 uri.

Does anyone know know if this usage is supported?

Best Answer

Prior to these changes it was required to create an archive within Glacier and place files within that archive. The link you referenced details how Glacier is now a storage class of S3. You no longer need to move files into Glacier, you can simply upload them as storage class GLACIER or DEEP_ARCHIVE. You can also change the storage type of existing files via the Permission tab or from the command line.

From the AWS CLI, you can use a command similar to this:

aws s3 cp /etc/hosts s3://faketest/hosts --storage-class GLACIER

You can see the storage class using s3api:

aws s3api list-objects --bucket faketest

To do this from the console, click on the Properties tab and select GLACIER

enter image description here

You can similarly set the storage class if you upload a file through the console.

For existing files you can change their storage class through the CLI using something similar to:

aws s3api copy-object --copy-source faketest/temp.txt --bucket faketest --storage-class GLACIER --key temp.txt

The above command copies an existing file from the bucket back to the same bucket with a change to storage class. There may be alternative methods to this.

References

Glacier FAQ
S3 CLI cp
S3 Storage Classes
s3api copy-object