amazon-web-services - 有没有办法使用 boto3 中的集群名称检查 emr 集群状态?
问题描述
在以下代码中,它可以使用 EMR id 检查 EMR 状态:
import boto3
client = boto3.client('emr')
response = emrClient.describe_cluster(ClusterId='j-XXXXXXXX')
我发现没有使用 emr 名称查询 emr 状态的 api。但是,我只有 emr 名称。如何使用 emr 名称检查我的 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 集群具有唯一名称时才有效。
推荐阅读
- angular6-json-schema-form - 项目数组的Angular6 JSON模式形式
- c - 在 C 语言中,我无法跟踪代码并且不确定如何计算该值?
- linux - 如何合并两个 kubectl 命令的输出
- r - 用`-`分割r中的月/年字符串
- python - Errno 13 权限被拒绝:'/test.txt'
- google-maps-api-3 - 巴黎和另一个法国城市之间的 Google Distance Matrix API 错误距离(随机问题)
- java - 接受多种http方法?
- django - 如何在循环中从 ForeignKey 关系中获取所有值?
- python-3.x - 如何在后台运行python创建一个独立的进程
- swift - 日期函数返回不正确的结果