Created
April 10, 2020 20:54
-
-
Save spenserpothier/391f3a6a6956b1674830991678f6fe6c to your computer and use it in GitHub Desktop.
Shell command to search through regions and profiles and return all `resourceNames` and `resourceIds` for a given ResourceType. meant to be sourced into an RC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findResourcesByType() { | |
if (($# == 0)) then | |
echo "\nUsage: findResourceByType <ResourceType>" | |
echo "\nResourceType list can be found at https://docs.aws.amazon.com/cli/latest/reference/configservice/list-discovered-resources.html#options" | |
return 1; | |
fi | |
# Fill these with the names of the profiles and regions you want to look through, space seperated | |
PROFILES=() | |
REGIONS=() | |
for o in $PROFILES; do | |
for i in $REGIONS; do | |
echo $fg[green]$o " " $i $reset_color | |
aws configservice list-discovered-resources --resource-type $1 --region $i --profile $o | jq -r '.resourceIdentifiers[]| "\t\(.resourceName) | \(.resourceId)"' | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment