【问题标题】:AWS ECS Docker Container Boto3 IAM PermissionsAWS ECS Docker 容器 Boto3 IAM 权限
【发布时间】:2016-12-26 01:36:29
【问题描述】:

我正在尝试使用 AWS ECS 在 docker 容器内运行 boto3 python 脚本。我的脚本需要访问 SQS(获取和删除消息)和 Lambda(搜索和运行权限)。

为了让 docker 容器在我的本地机器上运行,我可以使用以下 docker run 命令将我的 aws 凭据传递到 docker 容器中。

docker run -v ~/.aws:/root/.aws

最近ECS宣布:

Amazon ECS now supports IAM roles for tasks. When you specify an IAM role for a task, its containers can then use the latest versions of the AWS CLI or SDKs to make API requests to authorized AWS services. Learn More

我将任务 IAM 角色附加到任务,但在运行任务时出现以下错误:

Unable to run task ECS was unable to assume the role that was provided for this task. Please verify that the role being passed has the proper trust relationship and permissions and that your IAM user has permissions to pass this role.

任何想法将不胜感激。

【问题讨论】:

标签: amazon-web-services docker amazon-iam boto3


【解决方案1】:

Boto 现在似乎支持 IAM 任务角色,但无论如何,当 Boto 客户端尝试发出请求而不是尝试启动任务时,这将是一个问题。

这里的问题在错误消息中定义。要么:

1) 您的用户没有为任务角色定义的 iam:PassRole 权限。这可以通过编辑您的用户策略来添加类似于以下的语句:

{
  "Effect": "Allow",
  "Action": "iam:PassRole",
  "Resource": "arn:aws:iam::<account>:role/<role name>"
}

2) 您尝试分配给任务的任务角色没有正确的信任关系。将以下信任策略添加到 ECS 任务角色,以确保它可以由任务承担。

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

【讨论】:

    【解决方案2】:

    Boto3 将 botocore 库用于其 API 函数,并且它允许为每个 Boto3 版本提供一系列 botocore 版本,因此即使您拥有最新的 Boto3 版本,也可能没有最新的 botocore。

    自版本 1.4.37 起,Botocore 支持任务的 ECS IAM 角色,因此如果您将环境中的底层 botocore 更新到至少该版本,您应该能够使用任务的 ECS IAM 角色功能。

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 2022-01-04
      • 1970-01-01
      • 2021-08-13
      • 2020-11-15
      • 2020-12-26
      • 1970-01-01
      • 2018-12-06
      • 2021-07-30
      相关资源
      最近更新 更多