Skip to content

Instantly share code, notes, and snippets.

@spenserpothier
Created April 10, 2020 20:54
Show Gist options
  • Save spenserpothier/391f3a6a6956b1674830991678f6fe6c to your computer and use it in GitHub Desktop.
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
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