S3 Glacier examples using SDK for JavaScript (v3) (original) (raw)
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.
Actions
The following code example shows how to use CreateVault
.
SDK for JavaScript (v3)
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, seeCreateVault in AWS SDK for JavaScript API Reference.
The following code example shows how to use UploadArchive
.
SDK for JavaScript (v3)
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, seeUploadArchive in AWS SDK for JavaScript API Reference.
Did this page help you? - Yes
Thanks for letting us know we're doing a good job!
If you've got a moment, please tell us what we did right so we can do more of it.
Did this page help you? - No
Thanks for letting us know this page needs work. We're sorry we let you down.
If you've got a moment, please tell us how we can make the documentation better.