You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取运行中EMR集群的版本?多AWS账号场景下的操作指导

获取多AWS账号下活跃EMR集群的版本信息

先澄清一个关键误解

list-release-labels 这个命令的作用是列出AWS官方支持的所有EMR版本标签(比如emr-6.15.0、emr-7.0.0),并不是用来查询你已运行集群的版本。要获取现有活跃集群的版本,需要结合 list-clusters 和 describe-cluster 两个API操作。


单个AWS账号的操作步骤

  1. 获取所有活跃集群的ID
    首先用list-clusters拿到活跃集群的ID列表,这是后续查询的核心依据:

    aws emr list-clusters --active --query "Clusters[*].Id" --output text
    
  2. 批量查询每个集群的版本信息
    用bash循环遍历每个集群ID,调用describe-cluster提取集群名称和版本标签(ReleaseLabel字段):

    for cluster_id in $(aws emr list-clusters --active --query "Clusters[*].Id" --output text); do
      aws emr describe-cluster --cluster-id $cluster_id --query "Cluster.{集群名称:Name, EMR版本:ReleaseLabel}" --output table
    done
    

    执行后会以表格形式输出每个活跃集群的名称和对应的EMR版本,直观清晰。


多AWS账号的批量处理方案

如果你已经为每个AWS账号配置了CLI profile(比如account-dev、account-prod),可以通过遍历profile来批量查询:

# 替换成你的实际profile名称列表
accounts=("account-dev" "account-prod" "account-staging")

for profile in "${accounts[@]}"; do
  echo "=== 当前查询账号: $profile ==="
  # 获取该账号下的活跃集群ID
  cluster_ids=$(aws emr list-clusters --active --query "Clusters[*].Id" --output text --profile $profile)
  
  # 跳过无活跃集群的账号
  if [ -z "$cluster_ids" ]; then
    echo "该账号无活跃EMR集群"
    echo ""
    continue
  fi
  
  # 遍历集群ID查询版本
  for cluster_id in $cluster_ids; do
    aws emr describe-cluster --cluster-id $cluster_id --query "Cluster.{集群名称:Name, EMR版本:ReleaseLabel}" --output table --profile $profile
  done
  echo ""
done

补充说明

  • describe-cluster 返回的ReleaseLabel就是你需要的EMR集群版本,格式为emr-X.X.X;
  • 如果需要输出更简洁的格式(比如CSV),可以把--output table改成--output csv;
  • 确保你的AWS CLI有足够的权限(emr:ListClusters和emr:DescribeCluster)访问所有目标账号的EMR资源。

内容的提问来源于stack exchange,提问作者user2037551

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 17:45:39