【发布时间】:2022-01-25 06:51:52
【问题描述】:
我想使用 boto3 获取 EMR 集群的健康状态。 如果它是健康的,那么我应该能够运行我的作业。如何知道集群是否健康? 我运行了下面的代码,它返回了一个字典。
import boto3
emr_client = boto3.client('emr')
clusters = emr_client.list_clusters(ClusterStates=['STARTING', 'BOOTSTRAPPING', 'RUNNING', 'WAITING'])
for cluster in clusters['Clusters']:
cluster_id = cluster['Id']
response = emr_client.list_instances(ClusterId=cluster_id)
print(response)
输出:
{'Instances': [{'Id': 'ci-xxxx', 'Ec2InstanceId': 'i-xxxx', 'PublicDnsName': '', 'PrivateDnsName': 'ip-xxxx.ec2.internal', 'PrivateIpAddress': 'xxxx', 'Status': {'State': 'BOOTSTRAPPING', 'StateChangeReason': {}, 'Timeline': {'CreationDateTime': datetime.datetime(2021, 12, 27, 13, 8, 28, 758000, tzinfo=tzlocal())}}, 'InstanceGroupId': 'ig-xxxx', 'Market': 'ON_DEMAND', 'InstanceType': 'm5.xlarge', 'EbsVolumes': [{'Device': 'xxx', 'VolumeId': 'vol-xxx'}, {'Device': 'xxx', 'VolumeId': 'vol-xxxx'}]}, {'Id': 'ci-xxxx', 'Ec2InstanceId': 'i-xxxx', 'PublicDnsName': '', 'PrivateDnsName': 'ip-xxxx.ec2.internal', 'PrivateIpAddress': 'xxxx', 'Status': {'State': 'BOOTSTRAPPING', 'StateChangeReason': {}, 'Timeline': {'CreationDateTime': datetime.datetime(2021, 12, 27, 13, 8, 28, 758000, tzinfo=tzlocal())}}, 'InstanceGroupId': 'ig-xxxx', 'Market': 'ON_DEMAND', 'InstanceType': 'm5.xlarge', 'EbsVolumes': [{'Device': 'xxx', 'VolumeId': 'vol-xxxx'}, {'Device': 'xxx', 'VolumeId': 'vol-xxxx'}]}], 'ResponseMetadata': {'RequestId': 'xxxx', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'xxxx', 'content-type': 'application/x-amz-json-1.1', 'content-length': '989', 'date': 'Mon, 27 Dec 2021 19:08:55 GMT'}, 'RetryAttempts': 0}}
我们如何从中获取实例状态?而 list_instances 是查找 EMR 集群运行状况的正确方法吗?
谢谢。
【问题讨论】:
-
进展如何?仍然不清楚你能做什么?
-
嗨,Marcin,感谢您的宝贵时间。我尝试了以下代码: ``` import boto3 emr_client = boto3.client('emr') clusters = emr_client.list_clusters(ClusterStates=['STARTING', 'BOOTSTRAPPING', 'RUNNING', 'WAITING']) for cluster in clusters['Clusters']: cluster_id = cluster['Id'] response = emr_client.list_instances(ClusterId=cluster_id) print(response) ``` 输出是一个字典。请你帮助如何从上面获取实例ID输出并用于描述实例状态以获取实例的运行状况?谢谢。
-
我建议用新代码和错误创建一个新的。
-
我看到了新问题。那挺好的。我会看看,但如果我目前的回答有帮助,我们将不胜感激。
-
@Marcin 我已经更新了这里的问题......你能帮忙吗?感谢您的宝贵时间。
标签: python amazon-web-services amazon-ec2 boto3 amazon-emr