amazon-web-services - 使用 IAM 角色运行 Spark EC2 脚本

标签 amazon-web-services amazon-ec2 apache-spark amazon-iam

我正在尝试运行 Spark EC2 脚本以在我的 root 帐户下的用户可以承担的 IAM 角色下启动集群。

根据 this JIRA ticket ,我们现在可以指定 --profile运行 Spark EC2 脚本时,以及 comments on the pull request--profile option 指的是我认为的 AWSCLI 配置文件。

当我运行脚本时

ec2/spark-ec2 -k key-name -i key-name.pem -s 1 --profile myprofile --instance-type=t2.medium launch test-cluster

我得到
Profile "myprofile" not found!

然而,运行
aws s3 ls s3://mybucket --profile myprofile

按预期工作,导致我认为在 ~/.aws/config 中正确指定了 IAM 角色。 (我认为您没有在 ~/.aws/credentials 中指定 IAM 角色)。

但是,当我向 ~/.aws/credentials 添加测试配置文件时作为
[foobar]
aws_secret_access_key=xxxxxxx
aws_access_key_id=xxxxxxx

Spark 找到了 foobar轮廓。但是,添加后
[foobar]
role_arn = arn:aws:iam::12345:role/MY_ROLE
aws_secret_access_key=xxxxxxx
aws_access_key_id=xxxxxxx

Spark 找到了 foobar profile,但它没有正确登录到 IAM 角色。我得到
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidKeyPair.NotFound</Code><Message>The key pair 'key-name' does not exist</Message></Error></Errors><RequestID>fcebd475-a895-4a5b-9a29-9783fd6b7f3d</RequestID></Response>

这是因为 key 对 key-name不存在于我的用户之下,但它存在于我需要承担的 IAM 角色之下。这告诉我 Spark 没有正确登录到 IAM 角色。

我的 ~/.aws/config :
[default]
region = us-east-1
aws_secret_access_key = xxxxx
aws_access_key_id = xxxxx

[profile myprofile]
role_arn = arn:aws:iam::12345:role/MY_ROLE
source_profile = default

我的 ~/.aws/credentials :
[default]
aws_secret_access_key = xxxxx
aws_access_key_id = xxxxx

旁注-也尝试过:

手动承担角色
aws sts assume-role --role-arn arn:aws:iam::12345:role/MY_ROLE --role-session-name temp-session

然后导出 AWS_SECRET_ACCESS_KEY , AWS_SESSION_TOKEN , 和 AWS_ACCESS_KEY_ID到环境变量。
然后我在没有指定任何配置文件的情况下运行 EC2 脚本并得到
boto.exception.EC2ResponseError: EC2ResponseError: 401 Unauthorized
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to validate the provided access credentials</Message></Error></Errors><RequestID>11402f6e-074c-478c-84c1-11fb92ad0bff</RequestID></Response>

旁注-也尝试过:

根据 this JIRA on Spark scripts with IAM roles ,我们可以指定 --instance-profile-name (实例配置文件是否是以这种方式使用 IAM 角色的唯一方法?即.. 我是否必须向我们的管理员询问 IAM 列表/创建权限才能启动具有 IAM 角色的集群?)。我试过使用 arn:aws:iam::12345:role/MY_ROLEMY_ROLE但得到
boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>InvalidParameterValue</Code><Message>Value (arn:aws:iam::12345:role/MY_ROLE) for parameter iamInstanceProfile.name is invalid. Invalid IAM Instance Profile name</Message></Error></Errors><RequestID>ffeffef9-acad-4a34-a925-31f6b5bbbb3e</RequestID></Response>

最佳答案

我通过提供带有可传递配置文件名称的 spark-ec2 脚本的“--instance-profile-name”参数来管理将角色分配给 ec2 实例。

在实例内部确保运行

sudo yum update

也看看我的问题:
Running Spark EC2 scripts with IAM role

祝你好运

关于amazon-web-services - 使用 IAM 角色运行 Spark EC2 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36893992/

相关文章:

python - 亚马逊 AWS 任务自动化

mysql - 使用本地 MySQL 数据库保护 Web 服务器

.net - 处理不准确的系统时钟

python - 如何同时使用 substring 和 instr pyspark

amazon-web-services - AWS 中的 cloudformation 模板无法识别术语 'Events:'

.net - 您是否已将 .NET 计算应用程序部署到 Windows Azure 之外的云中?

amazon-web-services - Bluehosting 的 CNAME 问题?使用 AWS 负载均衡器

csv - 如何将具有大量列数的 csv 文件导入 Apache Spark 2.0

java - 调整 G1GC 参数以进行积极的垃圾收集?

amazon-web-services - 如何使用 cloudformation 从 S3 ARN 获取 S3 存储桶名称