Uploading an Archive to S3 Glacier - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

We announced the upcoming end-of-support for Amazon SDK for JavaScript v2. We recommend that you migrate to Amazon SDK for JavaScript v3. For dates, additional details, and information on how to migrate, please refer to the linked announcement.

Uploading an Archive to S3 Glacier

JavaScript code example that applies to Node.js execution

This Node.js code example shows:

  • How to upload an archive to Amazon S3 Glacier using the uploadArchive method of the S3 Glacier service object.

The following example uploads a single Buffer object as an entire archive using the uploadArchive method of the S3 Glacier service object.

The example assumes you've already created a vault named YOUR_VAULT_NAME. The SDK automatically computes the tree hash checksum for the data uploaded, though you can override it by passing your own checksum parameter:

Prerequisite Tasks

To set up and run this example, you must first complete these tasks:

Upload the Archive

// Load the SDK for JavaScript var AWS = require("aws-sdk"); // Set the region AWS.config.update({ region: "REGION" }); // Create a new service object and buffer var glacier = new AWS.Glacier({ apiVersion: "2012-06-01" }); buffer = Buffer.alloc(2.5 * 1024 * 1024); // 2.5MB buffer var params = { vaultName: "YOUR_VAULT_NAME", body: buffer }; // Call Glacier to upload the archive. glacier.uploadArchive(params, function (err, data) { if (err) { console.log("Error uploading archive!", err); } else { console.log("Archive ID", data.archiveId); } });