Creating a S3 Glacier vault - AWS SDK for JavaScript

Help us improve the AWS SDK for JavaScript version 3 (V3) documentation by providing feedback using the Feedback link, or create an issue or pull request on GitHub.

The AWS SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the AWS SDK for JavaScript version 3 (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 AWS 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 AWS 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.