There are more AWS SDK examples available in the AWS Doc SDK Examples
S3 Glacier examples using SDK for JavaScript (v3)
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for JavaScript (v3) with S3 Glacier.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use CreateVault
.
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Create the client.
const { GlacierClient } = require("@aws-sdk/client-glacier"); // Set the AWS Region. const REGION = "REGION"; //Set the Redshift Service Object const glacierClient = new GlacierClient({ region: REGION }); export { glacierClient };
Create the 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();
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see CreateVault in AWS SDK for JavaScript API Reference.
-
The following code example shows how to use UploadArchive
.
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Create the client.
const { GlacierClient } = require("@aws-sdk/client-glacier"); // Set the AWS Region. const REGION = "REGION"; //Set the Redshift Service Object const glacierClient = new GlacierClient({ region: REGION }); export { glacierClient };
Upload the archive.
// Load the SDK for JavaScript import { UploadArchiveCommand } from "@aws-sdk/client-glacier"; import { glacierClient } from "./libs/glacierClient.js"; // Set the parameters const vaultname = "VAULT_NAME"; // VAULT_NAME // Create a new service object and buffer const buffer = new Buffer.alloc(2.5 * 1024 * 1024); // 2.5MB buffer const params = { vaultName: vaultname, body: buffer }; const run = async () => { try { const data = await glacierClient.send(new UploadArchiveCommand(params)); console.log("Archive ID", data.archiveId); return data; // For unit tests. } catch (err) { console.log("Error uploading archive!", err); } }; run();
-
For more information, see AWS SDK for JavaScript Developer Guide.
-
For API details, see UploadArchive in AWS SDK for JavaScript API Reference.
-