There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DescribeJobs with an AWS SDK or CLI
The following code examples show how to use DescribeJobs.
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 examples:
- CLI
-
- AWS CLI
-
To describe a job
The following
describe-jobsexample describes a job with the specified job ID.aws batch describe-jobs \ --jobsbcf0b186-a532-4122-842e-2ccab8d54efbOutput:
{ "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 } ] }-
For API details, see DescribeJobs
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
. /** * 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()); }-
For API details, see DescribeJobs in AWS SDK for Java 2.x API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. def describe_jobs(self, job_ids: list) -> list: """ Describes one or more jobs. :param job_ids: A list of job IDs to describe. :return: A list of job detail dictionaries. """ try: response = self.batch_client.describe_jobs(jobs=job_ids) jobs = response.get("jobs", []) logger.info("Described %d job(s).", len(jobs)) return jobs except ClientError as err: logger.error( "Error describing jobs: %s", err.response["Error"]["Message"], ) raise-
For API details, see DescribeJobs in AWS SDK for Python (Boto3) API Reference.
-