Use ListVaults with an AWS SDK or CLI - Amazon S3 Glacier

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

If you're looking for archival storage solutions we suggest using the S3 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 S3 Glacier storage classes and Long-term data storage using S3 Glacier storage classes in the Amazon S3 User Guide. These storage classes use the Amazon S3 API, are available in all regions, and can be managed within the Amazon S3 console. They offer features like Storage Cost Analysis, Storage Lens, security features including multiple encryption options, and more.

Use ListVaults with an AWS SDK or CLI

The following code examples show how to use ListVaults.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// List the Amazon S3 Glacier vaults associated with the current account. /// </summary> /// <returns>A list containing information about each vault.</returns> public async Task<List<DescribeVaultOutput>> ListVaultsAsync() { var glacierVaultPaginator = _glacierService.Paginators.ListVaults( new ListVaultsRequest { AccountId = "-" }); var vaultList = new List<DescribeVaultOutput>(); await foreach (var vault in glacierVaultPaginator.VaultList) { vaultList.Add(vault); } return vaultList; }
  • For API details, see ListVaults in AWS SDK for .NET API Reference.

CLI
AWS CLI

The following command lists the vaults in the default account and region:

aws glacier list-vaults --account-id -

Output:

{ "VaultList": [ { "SizeInBytes": 3178496, "VaultARN": "arn:aws:glacier:us-west-2:0123456789012:vaults/my-vault", "LastInventoryDate": "2015-04-07T00:26:19.028Z", "VaultName": "my-vault", "NumberOfArchives": 1, "CreationDate": "2015-04-06T21:23:45.708Z" } ] }

Amazon Glacier requires an account ID argument when performing operations, but you can use a hyphen to specify the in-use account.

  • For API details, see ListVaults in AWS CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.glacier.model.ListVaultsRequest; import software.amazon.awssdk.services.glacier.model.ListVaultsResponse; import software.amazon.awssdk.services.glacier.GlacierClient; import software.amazon.awssdk.services.glacier.model.DescribeVaultOutput; import software.amazon.awssdk.services.glacier.model.GlacierException; import java.util.List; /** * 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 ListVaults { public static void main(String[] args) { GlacierClient glacier = GlacierClient.builder() .region(Region.US_EAST_1) .build(); listAllVault(glacier); glacier.close(); } public static void listAllVault(GlacierClient glacier) { boolean listComplete = false; String newMarker = null; int totalVaults = 0; System.out.println("Your Amazon Glacier vaults:"); try { while (!listComplete) { ListVaultsResponse response = null; if (newMarker != null) { ListVaultsRequest request = ListVaultsRequest.builder() .marker(newMarker) .build(); response = glacier.listVaults(request); } else { ListVaultsRequest request = ListVaultsRequest.builder() .build(); response = glacier.listVaults(request); } List<DescribeVaultOutput> vaultList = response.vaultList(); for (DescribeVaultOutput v : vaultList) { totalVaults += 1; System.out.println("* " + v.vaultName()); } // Check for further results. newMarker = response.marker(); if (newMarker == null) { listComplete = true; } } if (totalVaults == 0) { System.out.println("No vaults found."); } } catch (GlacierException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • For API details, see ListVaults in AWS SDK for Java 2.x API Reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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 list_vaults(self): """ Lists vaults for the current account. """ try: for vault in self.glacier_resource.vaults.all(): logger.info("Got vault %s.", vault.name) except ClientError: logger.exception("Couldn't list vaults.") raise
  • For API details, see ListVaults in AWS SDK for Python (Boto3) API Reference.

For a complete list of AWS SDK developer guides and code examples, see Using S3 Glacier with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.