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

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

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

SubmitJob配 AWS SDK或使用 CLI

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

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

CLI
AWS CLI

若要提交工作

此範例會將名為 example 的簡單容器工作提交至 HighPriority 工作佇列。

命令:

aws batch submit-job --job-name example --job-queue HighPriority --job-definition sleep60

輸出:

{ "jobName": "example", "jobId": "876da822-4198-45f2-a252-6cea32512ea8" }
  • 如需詳API細資訊,請參閱AWS CLI 指令參考SubmitJob中的。

Java
SDK對於爪哇 2.x
注意

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

/** * Submits a job asynchronously to the AWS Batch service. * * @param jobDefinitionName the name of the job definition to use * @param jobQueueName the name of the job queue to submit the job to * @param jobARN the Amazon Resource Name (ARN) of the job definition * @return a CompletableFuture that, when completed, contains the job ID of the submitted job */ public CompletableFuture<String> submitJobAsync(String jobDefinitionName, String jobQueueName, String jobARN) { SubmitJobRequest jobRequest = SubmitJobRequest.builder() .jobDefinition(jobARN) .jobName(jobDefinitionName) .jobQueue(jobQueueName) .build(); CompletableFuture<SubmitJobResponse> responseFuture = getAsyncClient().submitJob(jobRequest); responseFuture.whenComplete((response, ex) -> { if (ex != null) { throw new RuntimeException("Unexpected error occurred: " + ex.getMessage(), ex); } }); return responseFuture.thenApply(SubmitJobResponse::jobId); }
  • 如需詳API細資訊,請參閱AWS SDK for Java 2.x API參考SubmitJob中的。