AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或ListVaults
一起使用 CLI
以下代码示例演示如何使用 ListVaults
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <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; }
-
有关API详细信息,请参阅 “AWS SDK for .NET API参考 ListVaults” 中的。
-
- CLI
-
- AWS CLI
-
以下命令列出默认账户和区域中的文件库:
aws glacier list
-
vaults --account-id -输出:
{ "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 在执行操作时需要一个账户 ID 参数,但您可以使用连字符来指定正在使用的账户。
-
有关API详细信息,请参阅 “ListVaults AWS CLI
命令参考”。
-
- Java
-
- SDK适用于 Java 2.x
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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); } } }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ListVaults” 中的。
-
- Python
-
- SDK适用于 Python (Boto3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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
-
有关API详细信息,请参阅ListVaults中的 AWS SDKPython (Boto3) API 参考。
-
ListTagsForVault
SetVaultNotifications