繁体   English   中英

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

[英]List all "Active" EMR cluster using Boto3

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

我正在尝试使用 boto3 执行此操作

1) 列出所有活动的 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

谢谢

以下代码可以打印活动的 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.zheng 的回答略有更新:

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 对象中有所需的参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM