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

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

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

与 AWS SDK或CreateContainer一起使用 CLI

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

CLI
AWS CLI

创建容器

以下create-container示例创建一个新的空容器。

aws mediastore create-container --container-name ExampleContainer

输出:

{ "Container": { "AccessLoggingEnabled": false, "CreationTime": 1563557265, "Name": "ExampleContainer", "Status": "CREATING", "ARN": "arn:aws:mediastore:us-west-2:111122223333:container/ExampleContainer" } }

有关更多信息,请参阅 AWS Elemental MediaStore 用户指南中的创建容器

Java
SDK适用于 Java 2.x
注意

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

import software.amazon.awssdk.services.mediastore.MediaStoreClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.mediastore.model.CreateContainerRequest; import software.amazon.awssdk.services.mediastore.model.CreateContainerResponse; import software.amazon.awssdk.services.mediastore.model.MediaStoreException; /** * 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 CreateContainer { public static long sleepTime = 10; public static void main(String[] args) { final String usage = """ Usage: <containerName> Where: containerName - The name of the container to create. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String containerName = args[0]; Region region = Region.US_EAST_1; MediaStoreClient mediaStoreClient = MediaStoreClient.builder() .region(region) .build(); createMediaContainer(mediaStoreClient, containerName); mediaStoreClient.close(); } public static void createMediaContainer(MediaStoreClient mediaStoreClient, String containerName) { try { CreateContainerRequest containerRequest = CreateContainerRequest.builder() .containerName(containerName) .build(); CreateContainerResponse containerResponse = mediaStoreClient.createContainer(containerRequest); String status = containerResponse.container().status().toString(); while (!status.equalsIgnoreCase("Active")) { status = DescribeContainer.checkContainer(mediaStoreClient, containerName); System.out.println("Status - " + status); Thread.sleep(sleepTime * 1000); } System.out.println("The container ARN value is " + containerResponse.container().arn()); System.out.println("Finished "); } catch (MediaStoreException | InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } } }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 CreateContainer” 中的。