繁体   English   中英

无法使用 !Ref 在 Cloudformation 中创建 AWS Batch JobDefinition JobRoleArn

[英]Can't create a AWS Batch JobDefinition JobRoleArn in Cloudformation using a !Ref

我正在尝试在 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

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

调用 RegisterJobDefinition 操作时发生错误(ClientException):执行请求时出错,异常:executionRoleArn bothrefs-SecretsAndS3AccessRole-1INAOWFBH2SK2 is not an iam role arn

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

ExecutionRoleArn不允许!Ref有什么不同? 根据JobDefinition/ContainerProperties 的文档JobRoleArnExecutionRoleArn似乎与 object 相同。

!Ref返回资源的逻辑 ID,而不是 ARN。 你需要使用.GetAtt。

这应该有效:

ExecutionRoleArn: !GetAtt SecretsAndS3AccessRole.Arn

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM