Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload a file to Amazon Glacier Deep Archive using boto3

I've managed to upload a file to Glacier, but I want to upload to Deep Archive directly. I've searched the documentation, but found no mentions of how to set the storage class to DEEP_ARCHIVE directly.

like image 840
gahag Avatar asked Nov 25 '19 19:11

gahag


People also ask

How do you upload files to Glacier vault?

To upload data, such as photos, videos, and other documents, you must either use the AWS CLI or write code to make requests, by using either the REST API directly or by using the Amazon SDKs. For information about using S3 Glacier with the AWS CLI, go to AWS CLI Reference for S3 Glacier.

Can we move data directly to Glacier deep archive?

The easiest way to store data in S3 Glacier Deep Archive is to use the S3 PUT API to upload data directly. You can also upload data to S3 Glacier Deep Archive over the internet or using AWS Direct Connect and the AWS Management Console, AWS Storage Gateway, AWS Command Line Interface, or the AWS SDKs.

How do I transfer data from S3 to Glacier?

Store the data in 2 "folders" in S3, "standard" and "glacier". Set a lifecycle policy to push all objects in the "glacier" folder to Glacier data storage ASAP. When you want to move an object from standard to glacier, copy it to the glacier folder and delete the object in the standard folder (there's no "move" API).

Can we move data directly to AWS Glacier?

Currently, there is no way of uploading objects directly to S3 Glacier using a Snowball Edge. Thus, you first have to upload your objects into S3 Standard, and then use S3 lifecycle policies to transition the files to S3 Glacier.


1 Answers

You can either use put_object(), which has a StorageClass parameter, or you can use upload_file() while specifying ExtraArgs:

import boto3

s3_client = boto3.client('s3')

s3_client.upload_file('/tmp/hello.txt', 'my-bucket', 'hello.txt', ExtraArgs={'StorageClass': 'DEEP_ARCHIVE'})

Permitted ExtraArgs can be found at ALLOWED_UPLOAD_ARGS.

To clarify: This is uploading to Amazon S3 but setting the Storage Class to Glacier Deep Archive. This is different to uploading to the Amazon Glacier service. (These days it is easier to use Glacier via S3 storage classes).

like image 51
John Rotenstein Avatar answered Sep 28 '22 12:09

John Rotenstein