Get latest job revision while submitting AWS batch job without specifying the exact revision number
Asked Answered
E

3

9

I am using AWSBatch Java client com.amazonaws.services.batch (AWS SDK for Java - 1.11.483) to submit jobs programmatically.

However, our scientists keep updating the job definition. Every time there is a new job definition, I have to update the environment variable with the revision number to pass it to the client. AWS documentation states that

This value can be either a name:revision or the Amazon Resource Name (ARN) for the job definition.

Is there any way I can default it to the latest revision and every time I submit a BatchJob, the latest revision will get picked without even knowing the last revision?

Elka answered 29/1, 2019 at 22:12 Comment(0)
W
15

This value can be either a name:revision or the Amazon Resource Name (ARN) for the job definition.

Seems like AWS didn't document this properly: revision is optional, you can use simply use name instead of name:revision and it will get the ACTIVE revision of your job definition. It's also optional for Job Definition ARNs.

This also applies for boto3 and for AWS Step Functions integration with AWS Batch, and probably all other interfaces where Job Definition name or ARN are required.

Wheal answered 6/3, 2019 at 19:52 Comment(3)
I cannot find this documentation anywhere! Also, if there is more than one ACTIVE revision, is it safe to assume that the "latest" one will be picked up?Elka
AWS Documentation is open-source, so you can submit a pull request to github.com/awsdocs/aws-batch-user-guide if you find the time to do so. As for your second question, can there even be more that one ACTIVE revision for one job definition? I assumed there can't be.Wheal
There can be. I have a few revisions that are ACTIVE.Elka
F
6

From AWS Batch SubmitJob API reference.

jobDefinition

The job definition used by this job. This value can be one of name, name:revision, or the Amazon Resource Name (ARN) for the job definition. If name is specified without a revision then the latest active revision is used.

perhaps the documentation is updated by now.

Fogged answered 25/9, 2020 at 9:9 Comment(0)
E
0

I could not find any Java SDK function but I ended up using a bash script that fetches the latest* revision number from AWS.

$ aws batch describe-job-definitions  --job-definition-name ${full_name}  \
   --query='jobDefinitions[?status==`ACTIVE`].revision'  --output=json \
   --region=${region} | jq '.[0]'

(*) The .[0] will pick the first object from a list of active revisions, I used this because, by default, AWS Batch adds the latest revision to the top. You can set it as .[-1] if you want the last one.

Elka answered 19/2, 2019 at 0:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.