我正在尝试运行 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_ROLE
和 MY_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/