AWS SDK for Go
Developer Guide

Amazon S3 Glacier Examples Using the AWS SDK for Go

Amazon S3 Glacier is a secure, durable, and extremely low-cost cloud storage service for data archiving and long-term backup. The AWS SDK for Go examples can integrate Amazon S3 Glacier into your applications. The examples assume you have already set up and configured the SDK (that is, you've imported all required packages and set your credentials and region). For more information, see Getting Started with the AWS SDK for Go and Configuring the AWS SDK for Go.

You can download complete versions of these example files from the aws-doc-sdk-examples repository on GitHub.

The Scenario

Amazon S3 Glacier is a secure cloud storage service for data archiving and long-term backup. The service is optimized for infrequently accessed data where a retrieval time of several hours is suitable. These examples show you how to create a vault and upload an archive with Go. The methods used include:


Create a Vault

The following example uses the Amazon S3 GlacierCreateVault operation to create a vault named YOUR_VAULT_NAME.

svc := glacier.New(session.New(&aws.Config{Region: aws.String("us-west-2")})) _, err := svc.CreateVault(&glacier.CreateVaultInput{ VaultName: aws.String("YOUR_VAULT_NAME"), }) if err != nil { log.Println(err) return } log.Println("Created vault!")

Upload an Archive

The following example assumes you have a vault named YOUR_VAULT_NAME. It uses the Amazon S3 GlacierUploadArchive operation to upload a single reader object as an entire archive. The AWS SDK for Go automatically computes the tree hash checksum for the data to be uploaded.

vaultName := "YOUR_VAULT_NAME" svc := glacier.New(session.New(&aws.Config{Region: aws.String("us-west-2")})) result, err := svc.UploadArchive(&glacier.UploadArchiveInput{ AccountId: aws.String("-"), VaultName: &vaultName, Body: bytes.NewReader(make([]byte, 2*1024*1024)), // 2 MB buffer }) if err != nil { log.Println("Error uploading archive.", err) return } log.Println("Uploaded to archive", *result.ArchiveId)