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?

IamAshay
  • 1,377
  • 1
  • 7
  • 16

3 Answers3

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.

Ilya Sotkov
  • 166
  • 1
  • 4
  • 1
    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? – IamAshay Apr 04 '19 at 21:57
  • AWS Documentation is open-source, so you can submit a pull request to https://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. – Ilya Sotkov Apr 05 '19 at 12:33
  • 1
    There can be. I have a few revisions that are `ACTIVE`. – IamAshay Apr 09 '19 at 18:47
5

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.

piyumi_rameshka
  • 320
  • 4
  • 9
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.

IamAshay
  • 1,377
  • 1
  • 7
  • 16