AWS 文档 SDK 示例
将 CreateJobQueue 与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 CreateJobQueue。
操作示例是大型程序的代码摘录,必须在上下文中运行。您可以在以下代码示例中查看此操作的上下文:
- CLI
-
- AWS CLI
-
创建包含单一计算环境的低优先级作业队列
此示例创建一个名为 LowPriority 且使用 M4Spot 计算环境的作业队列。
命令:
aws batch create-job-queue --cli-input-jsonfile://<path_to_json_file>/LowPriority.jsonJSON 文件格式:
{ "jobQueueName": "LowPriority", "state": "ENABLED", "priority": 10, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "M4Spot" } ] }输出:
{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/LowPriority", "jobQueueName": "LowPriority" }创建包含两个计算环境的高优先级作业队列
此示例创建一个名为 HighPriority 的作业队列,该队列使用顺序为 1 的 C4OnDemand 计算环境和顺序为 2 的 M4Spot 计算环境。调度器将首先尝试在 C4OnDemand 计算环境中放置作业。
命令:
aws batch create-job-queue --cli-input-jsonfile://<path_to_json_file>/HighPriority.jsonJSON 文件格式:
{ "jobQueueName": "HighPriority", "state": "ENABLED", "priority": 1, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "C4OnDemand" }, { "order": 2, "computeEnvironment": "M4Spot" } ] }输出:
{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "jobQueueName": "HighPriority" }-
有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 CreateJobQueue
。
-
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
查看 GitHub,了解更多信息。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /** * Creates a job queue asynchronously. * * @param jobQueueName the name of the job queue to create * @param computeEnvironmentName the name of the compute environment to associate with the job queue * @return a CompletableFuture that completes with the Amazon Resource Name (ARN) of the job queue */ public CompletableFuture<String> createJobQueueAsync(String jobQueueName, String computeEnvironmentName) { if (jobQueueName == null || jobQueueName.isEmpty()) { throw new IllegalArgumentException("Job queue name cannot be null or empty"); } if (computeEnvironmentName == null || computeEnvironmentName.isEmpty()) { throw new IllegalArgumentException("Compute environment name cannot be null or empty"); } CreateJobQueueRequest request = CreateJobQueueRequest.builder() .jobQueueName(jobQueueName) .priority(1) .computeEnvironmentOrder(ComputeEnvironmentOrder.builder() .computeEnvironment(computeEnvironmentName) .order(1) .build()) .build(); CompletableFuture<CreateJobQueueResponse> response = getAsyncClient().createJobQueue(request); response.whenComplete((resp, ex) -> { if (ex != null) { String errorMessage = "Unexpected error occurred: " + ex.getMessage(); throw new RuntimeException(errorMessage, ex); } }); return response.thenApply(CreateJobQueueResponse::jobQueueArn); }-
有关 API 详细信息,请参阅《AWS SDK for Java 2.x API Reference》中的 CreateJobQueue。
-
CreateComputeEnvironment
DeleteComputeEnvironment