amazon-web-services - 无法使用 !Ref 在 Cloudformation 中创建 AWS Batch JobDefinition JobRoleArn

标签 amazon-web-services aws-cloudformation aws-batch

我正在尝试在 Cloudformation 中创建批量设置。我在资源中有一个 IAM 角色:

  SecretsAndS3AccessRole:
    Type: 'AWS::IAM::Role'
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service: batch.amazonaws.com
            Action: 'sts:AssumeRole'
          - Effect: Allow
            Principal:
              Service: ec2.amazonaws.com
            Action: 'sts:AssumeRole'
          - Effect: Allow
            Principal:
              Service: ecs-tasks.amazonaws.com
            Action: 'sts:AssumeRole'
      ManagedPolicyArns:
        - 'arn:aws:iam::aws:policy/SecretsManagerReadWrite'
        - 'arn:aws:iam::aws:policy/AmazonS3FullAccess'
        - 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'

然后在我的 JobDefinition 中我有:

  JobDefinition:
    Type: 'AWS::Batch::JobDefinition'
    Properties:
      Type: container
      ContainerProperties:
        Image: public.ecr.aws/l0v4l2q2/rapidtide-cloud
        Vcpus: 2
        Memory: 2000
        Command:
          - /simple-test
        Privileged: true
        JobRoleArn: !Ref SecretsAndS3AccessRole
        ExecutionRoleArn: !Ref SecretsAndS3AccessRole
        Secrets:
          - Name: MY_SECRET
            ValueFrom: arn:aws:secretsmanager:us-east-1:123456789:secret:MYSECRET-zSQVSQ
      RetryStrategy:
        Attempts: 1

当我尝试构建堆栈时,我得到:

An error occurred (ClientException) when calling the RegisterJobDefinition operation: Error executing request, Exception : executionRoleArn bothrefs-SecretsAndS3AccessRole-1INAOWFBH2SK2 is not an iam role arn

如果我删除 ExecutionRoleArn 行和 Secrets,堆栈构建得很好,也就是说 JobRoleArn!Ref SecretsAndS3AccessRole 的值感到满意。 (但我需要 secret ,并且要使用 secret ,您需要执行角色。)如果我在那里对 ARN 进行硬编码,它就可以正常工作。

ExecutionRoleArn 有何不同之处,它不允许 !Ref?根据 the documentation for JobDefinition/ContainerPropertiesJobRoleArnExecutionRoleArn 似乎是同一类型的对象。

最佳答案

!Ref 返回资源的逻辑 ID,而不是 ARN。 You need to use !GetAtt.

这应该有效:

ExecutionRoleArn: !GetAtt SecretsAndS3AccessRole.Arn

关于amazon-web-services - 无法使用 !Ref 在 Cloudformation 中创建 AWS Batch JobDefinition JobRoleArn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73871699/

相关文章:

amazon-web-services - 通过 Cloudformation 配置时,SNS 主题不会发送管道事件更改电子邮件

amazon-ecs - 获取 AWS Batch 集群名称 CDK

amazon-web-services - 如何使AWS Batch Volume持久化?

aws-cloudformation - AWS Cloudformation 创建 AWS Cloudwatch 事件以触发 AWS Batch

api - Amazon EC2 实例远程启动

swift - 无法从 AWS S3、Swift 3 下载图像

amazon-web-services - AWS SAM(无服务器应用程序模型)和无服务器框架有什么区别?

amazon-web-services - 在 bash 中使用 ec2 命令行工具获取 ec2 实例的公共(public) dns 名称

amazon-web-services - AWS CDK 生成的资源标识符非常糟糕且不可读。有任何解决这个问题的方法吗?

aws-cloudformation - CloudFormation - 以 Ubuntu 用户身份运行的用户数据