与 AWS SDK或ListContainers一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或ListContainers一起使用 CLI

以下代码示例演示如何使用 ListContainers

CLI
AWS CLI

查看容器列表

以下list-containers示例显示了与您的账户关联的所有容器的列表。

aws mediastore list-containers

输出:

{ "Containers": [ { "CreationTime": 1505317931, "Endpoint": "https://aaabbbcccdddee.data.mediastore.us-west-2.amazonaws.com", "Status": "ACTIVE", "ARN": "arn:aws:mediastore:us-west-2:111122223333:container/ExampleLiveDemo", "AccessLoggingEnabled": false, "Name": "ExampleLiveDemo" }, { "CreationTime": 1506528818, "Endpoint": "https://fffggghhhiiijj.data.mediastore.us-west-2.amazonaws.com", "Status": "ACTIVE", "ARN": "arn:aws:mediastore:us-west-2:111122223333:container/ExampleContainer", "AccessLoggingEnabled": false, "Name": "ExampleContainer" } ] }

有关更多信息,请参阅 AWS Elemental MediaStore 用户指南中的查看容器列表

Java
SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.mediastore.MediaStoreClient; import software.amazon.awssdk.services.mediastore.model.Container; import software.amazon.awssdk.services.mediastore.model.ListContainersResponse; import software.amazon.awssdk.services.mediastore.model.MediaStoreException; 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 ListContainers { public static void main(String[] args) { Region region = Region.US_EAST_1; MediaStoreClient mediaStoreClient = MediaStoreClient.builder() .region(region) .build(); listAllContainers(mediaStoreClient); mediaStoreClient.close(); } public static void listAllContainers(MediaStoreClient mediaStoreClient) { try { ListContainersResponse containersResponse = mediaStoreClient.listContainers(); List<Container> containers = containersResponse.containers(); for (Container container : containers) { System.out.println("Container name is " + container.name()); } } catch (MediaStoreException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 ListContainers” 中的。