在提交 AWS 批处理作业时获取最新的作业修订版而不指定确切的修订号

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

我正在使用 AWSBatch Java 客户端 com.amazonaws.services.batch (AWS SDK for Java - 1.11.483) 以编程方式提交作业。

但是,我们的科学家不断更新工作定义。 每次有新的作业定义时,我都必须用修订号更新环境变量以将其传递给客户端。 AWS documentation 表示

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

有什么方法可以让我将其默认为最新修订版,并且每次我提交 BatchJob 时,最新修订版都会在不知道最后修订版的情况下被选中?

我找不到任何 Java SDK 函数,但我最终使用了一个 bash 脚本,该脚本从 AWS 获取最新*修订号。

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

(*) .[0] 将从活动修订列表中选择第一个对象,我使用它是因为默认情况下,AWS Batch 将最新修订添加到顶部。如果你想要最后一个,你可以设置为.[-1]

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

似乎 AWS 没有正确记录:revision 是可选的,您可以简单地使用 name 而不是 name:revision,它会得到 ACTIVE修订您的工作定义。它对于作业定义 ARN 也是可选的。

这也适用于 boto3 和 AWS Step Functions 与 AWS Batch 的集成,以及可能需要作业定义名称或 ARN 的所有其他接口。

来自 AWS Batch SubmitJob API 参考。

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.

也许文档现在已经更新了。