使用Boto3列出所有“活动”EMR集群

问题描述 投票:0回答:1

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

我试图用boto3做到这一点

1)列出所有Active EMR集群

aws emr list-clusters --active

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

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

群集ID

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

但是我在使用boto3的开始阶段被阻止了

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

print response

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

谢谢

python amazon-web-services boto3
1个回答
0
投票

以下代码可以打印活动的emr名称和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'])
© www.soinside.com 2019 - 2024. All rights reserved.