如何在 Cloudformation 模板中获取 JobQueue 和 JobDefinition 名称

How to get JobQueue and JobDefinition name in Cloudformation template

在 Cloudformation 模板中,如何获得 Batch::JobDefinition 和 Batch::JobQueue 名称,以便将它们作为变量传递给 Lambda?

我已经尝试使用 JobQueueName name QueueName 使用 !GetAtt 将其拉出,但在更新堆栈时都失败了。使用 !Ref 只会给我 arn,我不能在 JS SDK 中使用它来与批处理进行通信。

两种资源,AWS::Batch::JobQueue and AWS::Batch::JobDefinition, only have the function Ref enabled to return the arn, you can't get any other value of those resources. What you can do is to use the function Fn::Split and Fn::Select根据arn获取它们的名字。例如,

  1. 对于 JobQueue,使用 arn arn:aws:batch:us-east-1:111122223333:job-queue/HighPriority,此代码将 return HighPriority.

    JOB_QUEUE: !Select [1 , !Split ["/", !Select [5, !Split [":", !Ref JobQueue]]]]
    
  2. 对于 JobDefinition,使用 arn arn:aws:batch:us-east-1:111122223333:job-definition/test-gpu:2,此代码将 return test-gpu.

    JOB_DEFINITION: !Select [1 , !Split ["/", !Select [5, !Split [":", !Ref JobDefinition]]]]