botocore.exceptions.ClientError: An error occurred (AccessDeniedException)

botocore.exceptions.ClientError: An error occurred (AccessDeniedException)

我在从另一个批处理作业中提交 AWS 批处理作业时遇到问题:

我正在使用具有默认服务 AWSBatchServiceRole 和默认实例 ecsInstanceRole 的计算环境。我已经设置了一个工作定义 myjobdef,其工作角色 MyJobRole 包含 AWS 批处理上的操作 *,仅用于测试。它还具有信任关系:

{
"Version": "2012-10-17",
"Statement": [
    {
    "Effect": "Allow",
    "Principal": {
        "Service": "ecs-tasks.amazonaws.com"
    },
    "Action": "sts:AssumeRole"
    }
]
}

我正在使用 python 3.7 和最新的 boto3。当使用我自己的凭据从我的本地 docker 容器调用 batch_client.submit_job(...) 时,它有效。当 运行 来自具有上述角色的 AWS 批次中的相同内容时,我得到一个例外:

botocore.exceptions.ClientError: An error occurred (AccessDeniedException)
when calling the SubmitJob operation: User: arn:aws:sts::<account_id>:assumed-role/MyJobRole/xxxx-xxxx-xxx-xx is not authorized to perform: batch:SubmitJob on resource: arn:aws:batch:<region>:<account_id>:job-definition/my_job_def

有什么解决方法吗?

根据评论。已正确确定该问题是由 缺少权限 在批处理作业角色中执行 batch:SubmitJob 操作引起的。 action:

Submits an AWS Batch job from a job definition.