Creating a Vault in Amazon Glacier Using the Amazon SDK for Java - Amazon Glacier
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 (PDF).

This page is only for existing customers of the Amazon Glacier service using Vaults and the original REST API from 2012.

If you're looking for archival storage solutions, we recommend using the Amazon Glacier storage classes in Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, and S3 Glacier Deep Archive. To learn more about these storage options, see Amazon Glacier storage classes.

Amazon Glacier (original standalone vault-based service) will no longer accept new customers starting December 15, 2025, with no impact to existing customers. Amazon Glacier is a standalone service with its own APIs that stores data in vaults and is distinct from Amazon S3 and the Amazon S3 Glacier storage classes. Your existing data will remain secure and accessible in Amazon Glacier indefinitely. No migration is required. For low-cost, long-term archival storage, Amazon recommends the Amazon S3 Glacier storage classes, which deliver a superior customer experience with S3 bucket-based APIs, full Amazon Web Services Region availability, lower costs, and Amazon service integration. If you want enhanced capabilities, consider migrating to Amazon S3 Glacier storage classes by using our Amazon Solutions Guidance for transferring data from Amazon Glacier vaults to Amazon S3 Glacier storage classes.

Creating a Vault in Amazon Glacier Using the Amazon SDK for Java

The low-level API provides methods for all the vault operations, including creating and deleting vaults, getting a vault description, and getting a list of vaults created in a specific Amazon Web Services Region. The following are the steps to create a vault using the Amazon SDK for Java.

  1. Create an instance of the AmazonGlacierClient class (the client).

    You need to specify an Amazon Web Services Region in which you want to create a vault. All operations you perform using this client apply to that Amazon Web Services Region.

  2. Provide request information by creating an instance of the CreateVaultRequest class.

    Amazon Glacier (Amazon Glacier) requires you to provide a vault name and your account ID. If you don't provide an account ID, then the account ID associated with the credentials you provide to sign the request is used. For more information, see Using the Amazon SDK for Java with Amazon Glacier.

  3. Run the createVault method by providing the request object as a parameter.

    The response Amazon Glacier returns is available in the CreateVaultResult object.

The following Java code snippet illustrates the preceding steps. The snippet creates a vault in the us-west-2 Region. The Location it prints is the relative URI of the vault that includes your account ID, the Amazon Web Services Region, and the vault name.

AmazonGlacierClient client = new AmazonGlacierClient(credentials); client.setEndpoint("https://glacier.us-west-2.amazonaws.com.cn"); CreateVaultRequest request = new CreateVaultRequest() .withVaultName("*** provide vault name ***"); CreateVaultResult result = client.createVault(request); System.out.println("Created vault successfully: " + result.getLocation());
Note

For information about the underlying REST API, see Create Vault (PUT vault).

Example: Creating a Vault Using the Amazon SDK for Java

The following Java code example creates a vault in the us-west-2 Region (for more information on Amazon Web Services Regions, see Accessing Amazon Glacier). In addition, the code example retrieves the vault information, lists all vaults in the same Amazon Web Services Region, and then deletes the vault created.

For step-by-step instructions on how to run the following example, see Running Java Examples for Amazon Glacier Using Eclipse.

import java.io.IOException; import java.util.List; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.services.glacier.AmazonGlacierClient; import com.amazonaws.services.glacier.model.CreateVaultRequest; import com.amazonaws.services.glacier.model.CreateVaultResult; import com.amazonaws.services.glacier.model.DeleteVaultRequest; import com.amazonaws.services.glacier.model.DescribeVaultOutput; import com.amazonaws.services.glacier.model.DescribeVaultRequest; import com.amazonaws.services.glacier.model.DescribeVaultResult; import com.amazonaws.services.glacier.model.ListVaultsRequest; import com.amazonaws.services.glacier.model.ListVaultsResult; public class AmazonGlacierVaultOperations { public static AmazonGlacierClient client; public static void main(String[] args) throws IOException { ProfileCredentialsProvider credentials = new ProfileCredentialsProvider(); client = new AmazonGlacierClient(credentials); client.setEndpoint("https://glacier.us-east-1.amazonaws.com/"); String vaultName = "examplevaultfordelete"; try { createVault(client, vaultName); describeVault(client, vaultName); listVaults(client); deleteVault(client, vaultName); } catch (Exception e) { System.err.println("Vault operation failed." + e.getMessage()); } } private static void createVault(AmazonGlacierClient client, String vaultName) { CreateVaultRequest createVaultRequest = new CreateVaultRequest() .withVaultName(vaultName); CreateVaultResult createVaultResult = client.createVault(createVaultRequest); System.out.println("Created vault successfully: " + createVaultResult.getLocation()); } private static void describeVault(AmazonGlacierClient client, String vaultName) { DescribeVaultRequest describeVaultRequest = new DescribeVaultRequest() .withVaultName(vaultName); DescribeVaultResult describeVaultResult = client.describeVault(describeVaultRequest); System.out.println("Describing the vault: " + vaultName); System.out.print( "CreationDate: " + describeVaultResult.getCreationDate() + "\nLastInventoryDate: " + describeVaultResult.getLastInventoryDate() + "\nNumberOfArchives: " + describeVaultResult.getNumberOfArchives() + "\nSizeInBytes: " + describeVaultResult.getSizeInBytes() + "\nVaultARN: " + describeVaultResult.getVaultARN() + "\nVaultName: " + describeVaultResult.getVaultName()); } private static void listVaults(AmazonGlacierClient client) { ListVaultsRequest listVaultsRequest = new ListVaultsRequest(); ListVaultsResult listVaultsResult = client.listVaults(listVaultsRequest); List<DescribeVaultOutput> vaultList = listVaultsResult.getVaultList(); System.out.println("\nDescribing all vaults (vault list):"); for (DescribeVaultOutput vault : vaultList) { System.out.println( "\nCreationDate: " + vault.getCreationDate() + "\nLastInventoryDate: " + vault.getLastInventoryDate() + "\nNumberOfArchives: " + vault.getNumberOfArchives() + "\nSizeInBytes: " + vault.getSizeInBytes() + "\nVaultARN: " + vault.getVaultARN() + "\nVaultName: " + vault.getVaultName()); } } private static void deleteVault(AmazonGlacierClient client, String vaultName) { DeleteVaultRequest request = new DeleteVaultRequest() .withVaultName(vaultName); client.deleteVault(request); System.out.println("Deleted vault: " + vaultName); } }