Skip to content

Instantly share code, notes, and snippets.

@sansagara
Last active September 23, 2022 04:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sansagara/9223c330eb7154f3d467b69b5537d8d2 to your computer and use it in GitHub Desktop.
Save sansagara/9223c330eb7154f3d467b69b5537d8d2 to your computer and use it in GitHub Desktop.
Print a list of AWS EMR Cluster names with their respective Tags
#!/bin/bash
# lists all EMR Clusters along with their tags in the following format:
# cluster_id | $cluster_name | { tag_name: tag_value }
# depends on AWS CLI and JQ
```
for cluster in `aws emr list-clusters --active | jq .Clusters[].Id -r`; do
name=$(aws emr describe-cluster --cluster-id $cluster --query Cluster.Name)
tags=$(aws emr describe-cluster --cluster-id $cluster --query Cluster.Tags | jq -c '.[] | {(.Key): .Value}' )
echo $cluster '|' $name '|' $tags
done
```
@sansagara
Copy link
Author

sansagara commented Jul 24, 2019

Slightly different output format:

for cluster in `aws emr list-clusters --active | jq .Clusters[].Id -r`; do
    name=$(aws emr describe-cluster --cluster-id $cluster --query Cluster.Name | tr -d \")
    tags=$(aws emr describe-cluster --cluster-id $cluster --query Cluster.Tags | jq -c '.[] | {(.Key): .Value}' )
    echo $cluster ' ' $name ' ' $tags
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment