列出所有“有效"列表使用Boto3的EMR集群 [英] List all "Active" EMR cluster using Boto3

查看:53
本文介绍了列出所有“有效"列表使用Boto3的EMR集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用boto3列出EMR上的所有活动集群,但是我的代码似乎无法正常工作,它只会返回null.

I'm trying to list all active clusters on EMR using boto3 but my code doesn't seem to be working it just returns null.

我正在尝试使用boto3做到这一点

Im trying to do this using boto3

1)列出所有活动的EMR群集

1) list all Active EMR clusters

aws emr list-clusters --active

2)仅列出集群ID和活动集群的名称集群名称

2) List only Cluster id's and Names of the Active one's cluster names

aws emr list-clusters --active --query "Clusters[*].{Name:Name}" --output text

集群ID

aws emr list-clusters --active --query "Clusters[*].{ClusterId:Id}" --output text

但是我在使用boto3的开始阶段受阻

But i'm blocked in the starting stage of using boto3

import boto3
client = boto3.client("emr")
response = client.list_clusters(
    ClusterStates=[
        'STARTING',
    ],
)

print response

任何建议如何将这些CLI命令转换为boto3

Any suggestions how can i convert those CLI commands to boto3

谢谢

推荐答案

以下代码可以显示活动的emr名称和ID:

The following codes can print the active emr name and id:

import boto3
client = boto3.client("emr")
response = client.list_clusters(
    ClusterStates=[
        'STARTING', 'BOOTSTRAPPING', 'RUNNING', 'WAITING', 'TERMINATING'
    ]
)
for cluster in response['Clusters']:
    print(cluster['Name'])
    print(cluster['Id'])

这篇关于列出所有“有效"列表使用Boto3的EMR集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆