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

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

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

DescribeJobs配 AWS SDK或使用 CLI

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

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

CLI
AWS CLI

描述工作的步驟

下列describe-jobs範例說明具有指定工作 ID 的工作。

aws batch describe-jobs \ --jobs bcf0b186-a532-4122-842e-2ccab8d54efb

輸出:

{ "jobs": [ { "status": "SUBMITTED", "container": { "mountPoints": [], "image": "busybox", "environment": [], "vcpus": 1, "command": [ "sleep", "60" ], "volumes": [], "memory": 128, "ulimits": [] }, "parameters": {}, "jobDefinition": "arn:aws:batch:us-east-1:012345678910:job-definition/sleep60:1", "jobQueue": "arn:aws:batch:us-east-1:012345678910:job-queue/HighPriority", "jobId": "bcf0b186-a532-4122-842e-2ccab8d54efb", "dependsOn": [], "jobName": "example", "createdAt": 1480483387803 } ] }
  • 如需詳API細資訊,請參閱AWS CLI 指令參考DescribeJobs中的。

Java
SDK對於爪哇 2.x
注意

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

/** * Asynchronously retrieves the status of a specific job. * * @param jobId the ID of the job to retrieve the status for * @return a CompletableFuture that completes with the job status */ public CompletableFuture<String> describeJobAsync(String jobId) { DescribeJobsRequest describeJobsRequest = DescribeJobsRequest.builder() .jobs(jobId) .build(); CompletableFuture<DescribeJobsResponse> responseFuture = getAsyncClient().describeJobs(describeJobsRequest); return responseFuture.whenComplete((response, ex) -> { if (ex != null) { throw new RuntimeException("Unexpected error occurred: " + ex.getMessage(), ex); } }).thenApply(response -> response.jobs().get(0).status().toString()); }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考DescribeJobs中的。