Python 列出所有;主动的;使用Boto3的EMR集群

Python 列出所有;主动的;使用Boto3的EMR集群,python,amazon-web-services,boto3,Python,Amazon Web Services,Boto3,我试图使用boto3列出EMR上的所有活动集群,但我的代码似乎不起作用,它只返回null 我试着用boto3做这个 import boto3 client = boto3.client("emr") response = client.list_clusters( ClusterStates=[ 'STARTING', ], ) print response 1) 列出所有活动的EMR群集 aws emr list-clusters --active 2)

我试图使用boto3列出EMR上的所有活动集群,但我的代码似乎不起作用,它只返回null

我试着用boto3做这个

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

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

aws emr list-clusters --active
2) 仅列出群集id和活动群集的名称 群集名称

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

aws emr list-clusters --active --query "Clusters[*].{Name:Name}" --output text
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


谢谢

以下代码可以打印激活的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'])

稍微更新一下@shifu.郑的回答:

import boto3
client = boto3.client("emr",region_name = "us-west-1", aws_access_key_id = "sdufashdifos123121", aws_secret_access_key ="sjdfnsaldfoasd1231312")
response = client.list_clusters(ClusterStates=['STARTING', 'BOOTSTRAPPING', 'RUNNING', 'WAITING', 'TERMINATING'])
for cluster in response['Clusters']:
print(cluster['Name'])
print(cluster['Id'])

您需要在boto3.client对象中具有所需的参数。

如何阻止?与CLI的--active等效的boto3可能类似于ClusterState=['STARTING'、'BOOTSTRAPPING'、'RUNNING'、'WAITING'、'TERMINATING']。您可能只想获得集群的完整列表(不带过滤器),然后缩小代码中的列表范围。