Use SubmitJob with an AWS SDK or CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use SubmitJob with an AWS SDK or CLI

The following code examples show how to use SubmitJob.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

CLI
AWS CLI

To submit a job

This example submits a simple container job called example to the HighPriority job queue.

Command:

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

Output:

{ "jobName": "example", "jobId": "876da822-4198-45f2-a252-6cea32512ea8" }
  • For API details, see SubmitJob in AWS CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * 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); }
  • For API details, see SubmitJob in AWS SDK for Java 2.x API Reference.