Skip to content

Instantly share code, notes, and snippets.

@sansagara
Last active January 14, 2023 08:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sansagara/7e9a1322d38600e67466051413df2e72 to your computer and use it in GitHub Desktop.
List all EMR Clusters along with the associated EC2 Instance Ids
#!/bin/bash
# lists all EMR Clusters along with the associated EC2 Instance Ids
# Use this directly on your command shell. It will print the result in the format:
# "cluster_id | [$ec2_instance-id]... "
# depends on AWS CLI and JQ
for cluster in `aws emr list-clusters --active --query 'Clusters[].Id' --output text`; do
instances=$(aws emr list-instances --cluster-id ${cluster} --query 'Instances[?Status.State==`RUNNING`].[InstanceGroupId, InstanceType]' | jq -r -c '.[] | @tsv')
echo ${cluster} '|' ${instances//$'\n'/ }
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment