首页 > 解决方案 > 有没有办法使用 boto3 中的集群名称检查 emr 集群状态?

问题描述

在以下代码中,它可以使用 EMR id 检查 EMR 状态:

import boto3

client = boto3.client('emr')
response = emrClient.describe_cluster(ClusterId='j-XXXXXXXX')

我发现没有使用 emr 名称查询 emr 状态的 api。但是,我只有 emr 名称。如何使用 emr 名称检查我的 emr 状态?

标签: amazon-web-servicesamazon-emr

解决方案


您可以使用一种list_clusters方法列出所有现有集群,按名称过滤掉您要查找的集群并接收其 id 以用于describe_cluster.

看起来像:

import boto3

cluster_name = 'name_of_your_cluster'

client = boto3.client('emr')

clusters = client.list_clusters()
your_cluster = [i for i in clusters['Clusters'] if i['Name'] == cluster_name][0]
response = client.describe_cluster(ClusterId=your_cluster['Id'])

请注意,这仅在您的 EMR 集群具有唯一名称时才有效。


推荐阅读