首页 文章

使用IAM角色运行Spark EC2脚本

提问于
浏览
5

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

根据this JIRA ticket,我们现在可以在运行Spark EC2脚本时指定 --profile ,并且comments on the pull request表示 --profile 选项指的是我认为的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 Profiles . 但是,添加后

[foobar]
role_arn = arn:aws:iam::12345:role/MY_ROLE
aws_secret_access_key=xxxxxxx
aws_access_key_id=xxxxxxx

Spark找到 foobar 配置文件,但它没有正确登录到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-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_KEYAWS_SESSION_TOKENAWS_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>

1 回答

  • 0

    我通过向spark-ec2脚本提供'--instance-profile-name'参数来管理为ec2实例分配角色,您可以传递一个配置文件名称 .

    在实例内部确保运行

    sudo yum update
    

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

    祝好运

相关问题