gpt4 book ai didi

python - 使用 Boto3 列出所有 "Active"EMR 集群

转载 作者:行者123 更新时间:2023-12-01 08:20:31 24 4
gpt4 key购买 nike

我正在尝试使用 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'])

关于python - 使用 Boto3 列出所有 "Active"EMR 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54677831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com