Creating a S3 Glacier vault - 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.

The Amazon SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the Amazon SDK for JavaScript version 3 (V3).

Starting October 1, 2022, Amazon SDK for JavaScript (v3) will end support for Internet Explorer 11 (IE 11). For details, see Announcing the end of support for Internet Explorer 11 in the Amazon SDK for JavaScript (v3).

Creating a S3 Glacier vault

JavaScript code example that applies to Node.js execution

This Node.js code example shows:

  • How to create a vault using the CreateVaultCommand method of the Amazon S3 Glacier service object.

Prerequisite tasks

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

  • Set up the project environment to run these Node TypeScript examples, and install the required Amazon SDK for JavaScript and third-party modules. Follow the instructions on GitHub.

  • Create a shared configurations file with your user credentials. For more information about providing a shared credentials file, see Loading credentials in Node.js from the shared credentials file.

Important

These examples demonstrate how to import/export client service objects and command using ECMAScript6 (ES6).

Create the vault

Create a libs directory, and create a Node.js module with the file name glacierClient.js. Copy and paste the code below into it, which creates the S3 Glacier client object. Replace REGION with your Amazon Region.

import { GlacierClient } from "@aws-sdk/client-glacier"; // Set the AWS Region. const REGION = "REGION"; //e.g. "us-east-1" // Create Glacier service object. const glacierClient = new GlacierClient({ region: REGION }); export { glacierClient };

This example code can be found here on GitHub.

Create a Node.js module with the file name createVault.js. Copy and paste the code below into it.

Note

Replace VAULT_NAME with the name of the S3 Glacier vault.

// Load the SDK for JavaScript import { CreateVaultCommand } from "@aws-sdk/client-glacier"; import { glacierClient } from "./libs/glacierClient.js"; // Set the parameters const vaultname = "VAULT_NAME"; // VAULT_NAME const params = { vaultName: vaultname }; const run = async () => { try { const data = await glacierClient.send(new CreateVaultCommand(params)); console.log("Success, vault created!"); return data; // For unit tests. } catch (err) { console.log("Error"); } }; run();

To run the example, enter the following at the command prompt.

node createVault.js

This example code can be found here on GitHub.