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).
List Amazon S3 Glacier vaults using an Amazon SDK
The following code examples show how to list Amazon S3 Glacier vaults.
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
-
- Amazon SDK for .NET
-
/// <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;
}
- Java
-
- SDK for Java 2.x
-
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);
}
}
- Python
-
- SDK for 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 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 a complete list of Amazon SDK developer guides and code examples, see
Using S3 Glacier with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.