Esta página é somente para clientes atuais do serviço Amazon Glacier que usam Vaults e a API REST original de 2012.
Se você estiver procurando por soluções de armazenamento de arquivos, recomendamos usar as classes de armazenamento Amazon Glacier no Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval e S3 Glacier Deep Archive. Para saber mais sobre essas opções de armazenamento, consulte as classes de armazenamento do Amazon Glacier.
O Amazon Glacier (serviço autônomo original baseado em cofre) não aceitará mais novos clientes a partir de 15 de dezembro de 2025, sem impacto para os clientes existentes. O Amazon Glacier é um serviço independente APIs que armazena dados em cofres e é diferente das classes de armazenamento Amazon S3 e Amazon S3 Glacier. Seus dados existentes permanecerão seguros e acessíveis no Amazon Glacier indefinidamente. Nenhuma migração é necessária. Para armazenamento de arquivamento de baixo custo e longo prazo, AWS recomenda as classes de armazenamento Amazon S3 Glacier, que oferecem uma experiência superior ao cliente com APIs base em buckets S3, disponibilidade Região da AWS total, custos mais baixos e integração de serviços. AWS Se você quiser recursos aprimorados, considere migrar para as classes de armazenamento do Amazon S3 Glacier usando AWS nossa orientação de soluções para transferir dados dos cofres do Amazon Glacier para as classes de armazenamento do Amazon S3 Glacier.
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use CreateVault com um AWS SDK ou CLI
Os exemplos de código a seguir mostram como usar o CreateVault.
Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação em contexto no seguinte exemplo de código:
- .NET
-
- SDK para .NET
-
/// <summary>
/// Create an Amazon S3 Glacier vault.
/// </summary>
/// <param name="vaultName">The name of the vault to create.</param>
/// <returns>A Boolean value indicating the success of the action.</returns>
public async Task<bool> CreateVaultAsync(string vaultName)
{
var request = new CreateVaultRequest
{
// Setting the AccountId to "-" means that
// the account associated with the current
// account will be used.
AccountId = "-",
VaultName = vaultName,
};
var response = await _glacierService.CreateVaultAsync(request);
Console.WriteLine($"Created {vaultName} at: {response.Location}");
return response.HttpStatusCode == HttpStatusCode.Created;
}
- CLI
-
- AWS CLI
-
O seguinte comando cria um cofre chamado my-vault:
aws glacier create-vault --vault-name my-vault --account-id -
O Amazon Glacier exige um argumento de ID de conta ao realizar operações, mas você pode usar um hífen para especificar a conta em uso.
- Java
-
- SDK para Java 2.x
-
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.glacier.GlacierClient;
import software.amazon.awssdk.services.glacier.model.CreateVaultRequest;
import software.amazon.awssdk.services.glacier.model.CreateVaultResponse;
import software.amazon.awssdk.services.glacier.model.GlacierException;
/**
* Before running this Java V2 code example, set up your development
* environment, including your credentials.
*
* For more information, see the following documentation topic:
*
* https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html
*/
public class CreateVault {
public static void main(String[] args) {
final String usage = """
Usage: <vaultName>
Where:
vaultName - The name of the vault to create.
""";
if (args.length != 1) {
System.out.println(usage);
System.exit(1);
}
String vaultName = args[0];
GlacierClient glacier = GlacierClient.builder()
.region(Region.US_EAST_1)
.build();
createGlacierVault(glacier, vaultName);
glacier.close();
}
public static void createGlacierVault(GlacierClient glacier, String vaultName) {
try {
CreateVaultRequest vaultRequest = CreateVaultRequest.builder()
.vaultName(vaultName)
.build();
CreateVaultResponse createVaultResult = glacier.createVault(vaultRequest);
System.out.println("The URI of the new vault is " + createVaultResult.location());
} catch (GlacierException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
}
- JavaScript
-
- SDK para JavaScript (v3)
-
Crie o cliente.
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 };
Crie o cofre.
// 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();
- SDK para JavaScript (v2)
-
// Load the SDK for JavaScript
var AWS = require("aws-sdk");
// Set the region
AWS.config.update({ region: "REGION" });
// Create a new service object
var glacier = new AWS.Glacier({ apiVersion: "2012-06-01" });
// Call Glacier to create the vault
glacier.createVault({ vaultName: "YOUR_VAULT_NAME" }, function (err) {
if (!err) {
console.log("Created vault!");
}
});
- PowerShell
-
- Ferramentas para PowerShell V4
-
Exemplo 1: criar novo cofre para a conta do usuário. Como nenhum valor foi fornecido ao AccountId parâmetro -, os cmdlets usam o padrão “-” indicando a conta atual.
New-GLCVault -VaultName myvault
Saída:
/01234567812/vaults/myvault
- Ferramentas para PowerShell V5
-
Exemplo 1: criar novo cofre para a conta do usuário. Como nenhum valor foi fornecido ao AccountId parâmetro -, os cmdlets usam o padrão “-” indicando a conta atual.
New-GLCVault -VaultName myvault
Saída:
/01234567812/vaults/myvault
- Python
-
- SDK para Python (Boto3)
-
class GlacierWrapper:
"""Encapsulates Amazon S3 Glacier API operations."""
def __init__(self, glacier_resource):
"""
:param glacier_resource: A Boto3 Amazon S3 Glacier resource.
"""
self.glacier_resource = glacier_resource
def create_vault(self, vault_name):
"""
Creates a vault.
:param vault_name: The name to give the vault.
:return: The newly created vault.
"""
try:
vault = self.glacier_resource.create_vault(vaultName=vault_name)
logger.info("Created vault %s.", vault_name)
except ClientError:
logger.exception("Couldn't create vault %s.", vault_name)
raise
else:
return vault
Para obter uma lista completa dos guias do desenvolvedor do AWS SDK e exemplos de código, consulteUsando o Amazon Glacier com um SDK AWS. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.