AWS Batch CLIENT_ERROR 无效的 IamInstanceProfile

AWS Batch CLIENT_ERROR Invalid IamInstanceProfile

最初将其发布到 ServerFault,但在此发布是希望有人 运行 了解我的问题。

我正在尝试在 AWS Batch 上为 运行 设置一个容器。我没有做任何花哨的事情,或多或少只是遵循所有内容的默认设置。我收到似乎与实例角色或与实例角色关联的权限有关的错误。

一开始设置很顺利。我设置了我的计算环境,然后是我的队列,然后我将一个基本作业添加到队列中。该作业最终陷入 运行 可用状态,然后在 20 分钟左右后,我的计算环境变为 "INVALID" 并出现此错误:

CLIENT_ERROR - Invalid IamInstanceProfile: arn:aws:iam::001234567890:role/ecsInstanceRole (Service: AmazonAutoScaling; Status Code: 400; Error Code: ValidationError; Request ID: blah)

我读了 this troubleshooting guide,它似乎解决了相关问题(尽管它们并不完全匹配)。我试过 5 或 6 次重新创建环境,但都没有成功。我也试过删除我现有的角色并让经理重新创建它们。故障排除指南中的大多数问题似乎源于 AWS CLI 中错误设置的角色或一些非 Batch 控制台需求。该指南甚至显示 "the AWS Batch console only displays roles that have the correct trust relationship for compute environments"。但是我使用的所有角色都是通过控制台选择的,这似乎暗示它们已获得正确许可。

不知道该怎么做,感谢您的帮助。

感谢您提请我们注意此事。我们已经解决了这个问题的根本原因,控制台现在应该可以正常工作了。请再试一次,如果您遇到任何其他错误,请告诉我们。

来自 AWS Batch 团队的 Jamie

有点令人困惑,AWS Batch Compute Environment 的 instanceRole 属性 必须引用 IAM instance profile ARN 而不是 IAM role ARN。也就是说,instanceRole 值应该看起来像 arn:aws:iam::123456789012:instance-profile/ecsInstanceRole 而不是 arn:aws:iam::123456789012:role/ecsInstanceRole。不过,错误消息实际上提到了实例配置文件。

以下 CloudFormation 片段创建了一个有效的 Batch 计算环境:

Parameters:
    VPC:
        Type: String
        Description: VPC ID of the target VPC
    Subnet:
        Type: List<AWS::EC2::Subnet::Id>
        Description: VPC subnet(s) for batch instances
    SG:
        Type: List<AWS::EC2::SecurityGroup::Id>
        Description: VPC Security group ID(s) for batch instances

Resources:
    MyBatchEnvironment:
        Type: "AWS::Batch::ComputeEnvironment"
        Properties:
            Type: MANAGED
            ServiceRole: !GetAtt MyBatchEnvironmentRole.Arn
            ComputeResources:
                MaxvCpus: 8
                SecurityGroupIds: !Ref SG
                Subnets: !Ref Subnet
                InstanceRole: !GetAtt MyBatchInstanceProfile.Arn
                MinvCpus: 0
                DesiredvCpus: 0
                Type: EC2
                InstanceTypes:
                    - optimal

    MyBatchEnvironmentRole:
        Type: "AWS::IAM::Role"
        Properties:
            AssumeRolePolicyDocument:
                Version: '2012-10-17'
                Statement:
                    - Effect: Allow
                      Principal: {Service: "batch.amazonaws.com"}
                      Action: "sts:AssumeRole"
            Path: /service-role/
            ManagedPolicyArns:
                - "arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole"

    MyBatchInstanceRole:
        Type: "AWS::IAM::Role"
        Properties:
            AssumeRolePolicyDocument:
                Version: '2012-10-17'
                Statement:
                    - Effect: Allow
                      Principal: {Service: "ec2.amazonaws.com"}
                      Action: "sts:AssumeRole"
            Path: /
            ManagedPolicyArns:
                - "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"

    MyBatchInstanceProfile:
        Type: "AWS::IAM::InstanceProfile"
        Properties:
            Path: "/"
            Roles:
                - !Ref MyBatchInstanceRole