搭DescribeJobQueues配 AWS SDK或使用 CLI - AWS SDK 程式碼範例

AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

DescribeJobQueues配 AWS SDK或使用 CLI

下列程式碼範例會示範如何使用DescribeJobQueues

動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:

CLI
AWS CLI

描述工作佇列

此範例說明工 HighPriority 作佇列。

命令:

aws batch describe-job-queues --job-queues HighPriority

輸出:

{ "jobQueues": [ { "status": "VALID", "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "computeEnvironmentOrder": [ { "computeEnvironment": "arn:aws:batch:us-east-1:012345678910:compute-environment/C4OnDemand", "order": 1 } ], "statusReason": "JobQueue Healthy", "priority": 1, "state": "ENABLED", "jobQueueName": "HighPriority" } ] }
Java
SDK對於爪哇 2.x
注意

還有更多關於 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/** * Asynchronously describes the job queue associated with the specified compute environment. * * @param computeEnvironmentName the name of the compute environment to find the associated job queue for * @return a {@link CompletableFuture} that, when completed, contains the job queue ARN associated with the specified compute environment * @throws RuntimeException if the job queue description fails */ public CompletableFuture<String> describeJobQueueAsync(String computeEnvironmentName) { DescribeJobQueuesRequest describeJobQueuesRequest = DescribeJobQueuesRequest.builder() .build(); CompletableFuture<DescribeJobQueuesResponse> responseFuture = getAsyncClient().describeJobQueues(describeJobQueuesRequest); return responseFuture.whenComplete((describeJobQueuesResponse, ex) -> { if (describeJobQueuesResponse != null) { String jobQueueARN; for (JobQueueDetail jobQueueDetail : describeJobQueuesResponse.jobQueues()) { for (ComputeEnvironmentOrder computeEnvironmentOrder : jobQueueDetail.computeEnvironmentOrder()) { String computeEnvironment = computeEnvironmentOrder.computeEnvironment(); String name = getComputeEnvironmentName(computeEnvironment); if (name.equals(computeEnvironmentName)) { jobQueueARN = jobQueueDetail.jobQueueArn(); logger.info("Job queue ARN associated with the compute environment: " + jobQueueARN); } } } } else { throw new RuntimeException("Failed to describe job queue: " + ex.getMessage(), ex); } }).thenApply(describeJobQueuesResponse -> { String jobQueueARN = ""; for (JobQueueDetail jobQueueDetail : describeJobQueuesResponse.jobQueues()) { for (ComputeEnvironmentOrder computeEnvironmentOrder : jobQueueDetail.computeEnvironmentOrder()) { String computeEnvironment = computeEnvironmentOrder.computeEnvironment(); String name = getComputeEnvironmentName(computeEnvironment); if (name.equals(computeEnvironmentName)) { jobQueueARN = jobQueueDetail.jobQueueArn(); } } } return jobQueueARN; }); }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考DescribeJobQueues中的。