我已经在这个网站和谷歌上搜索过了,但还没有得到答案。
我有从一个EC2实例运行的代码,该实例使用boto创建和管理EMR集群。我可以使用这个框架来获取flow_id (或cluster_id,不确定哪个是它的正确名称),它以"j-“开头,并有固定数量的字符来标识集群。
使用框架,我可以建立电子病历或ec2连接,但在我的生命中,我不能使用boto做以下事情:
aws emr --list-clusters --cluster-id=j-ASDFGHJKL | json '["instances"].[0].["privateipaddress"]**上面有点模糊,我记不清json格式和json命令是什么,或者它想要什么参数,但cli仍然记得。
我已经使用inspect.getmembers()对连接进行了pprint.pprint()和检查,获得了特定cluster_id的conn,但无论是否进行方法调用,我都还没有看到这个字段/var/属性。
我在亚马逊和boto上上下下,他们是怎么像here那样做的?
在
def test_list_instances(self): #line 317
...
self.assertEqual(response.instances[0].privateipaddress , '10.0.0.60')
...附注:我尝试过this,但python抱怨"instances“属性不可迭代,数组不可访问(我忘记了"var”命名),以及我尝试过的其他东西,包括检查。顺便说一句,我可以从这里访问publicDNSaddress,以及许多其他东西,只是不能访问privateIP...
请告诉我,如果我在哪里可以找到答案,我正在使用子进程使用一个丑陋的修复程序!
发布于 2019-04-24 22:46:33
如果您请求获取emr的主ip,则可以使用以下命令:
list_intance_resp = boto3.client('emr',region_name='us-east-1').list_instances(ClusterId ='j-XXXXXXX')
print list_intance_resp['Instances'][len(list_intance_resp['Instances'])-1]['PrivateIpAddress']发布于 2014-11-05 03:23:33
使用pip show boto检查您的boto版本我猜您使用的是2.24或更早版本,因为此版本不能解析实例信息请参阅https://github.com/boto/boto/blob/2.24.0/tests/unit/emr/test_connection.py#L117与https://github.com/boto/boto/blob/2.25.0/tests/unit/emr/test_connection.py#L313的比较
如果您将boto版本升级到2.25或更高版本,您将能够执行以下操作
from boto.emr.connection import EmrConnection
conn = EmrConnection(<your aws key>, <your aws secret key>)
jobid = 'j-XXXXXXXXXXXXXX' # your job id
response = conn.list_instances(jobid)
for instance in response.instances:
print instance.privateipaddress 发布于 2020-07-29 13:10:53
您只需借助EMR cluster-ID查询主实例组中的主实例即可。如果您有多个主机,则可以解析boto3输出,并获取列出的第一个主机的IP。
您的Boto3执行环境应该能够访问电子病历描述集群及其实例组。下面是
emr_list_instance_rep = boto_client_emr.list_instances(
ClusterId=cluster_id,
InstanceGroupTypes=[
'MASTER',
],
InstanceStates=[
'RUNNING',
]
)
return emr_list_instance_rep["Instances"][0]["PrivateIpAddress"]您可以在https://scriptcrunch.com/script-retrieve-aws-emr-master-ip/中找到完整的boto3脚本及其解释
https://stackoverflow.com/questions/26228091
复制相似问题