AWS SDK または CLI CreateJobQueueで を使用する - AWS SDK コード例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK または CLI CreateJobQueueで を使用する

以下のコード例は、CreateJobQueue の使用方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

CLI
AWS CLI

単一のコンピューティング環境で優先度の低いジョブキューを作成する方法

この例では、M4Spot コンピューティング環境を使用する LowPriority というジョブキューを作成します。

コマンド:

aws batch create-job-queue --cli-input-json file://<path_to_json_file>/LowPriority.json

JSON ファイル形式:

{ "jobQueueName": "LowPriority", "state": "ENABLED", "priority": 10, "computeEnvironmentOrder": [ { "order": 1, "computeEnvironment": "M4Spot" } ] }

出力:

{ "jobQueueArn": "arn:aws:batch:us-east-1:012345678910:job-queue/LowPriority", "jobQueueName": "LowPriority" }

2 つのコンピューティング環境で優先度の高いジョブキューを作成する方法

この例では、1 の順序で C4OnDemand コンピューティング環境を使用し、2 の順序で M4Spot コンピューティング環境を使用する、HighPriority というジョブキューを作成します。スケジューラは、まず C4OnDemand コンピューティング環境にジョブを配置しようとします。

コマンド:

aws batch create-job-queue --cli-input-json file://<path_to_json_file>/HighPriority.json

JSON ファイル形式:

{ "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
SDK for Java 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 CreateJobQueue」を参照してください。