Skip to content

Instantly share code, notes, and snippets.

@ollytheninja
Created May 28, 2023 23:05
Show Gist options
  • Save ollytheninja/c5533d74f59991dfd23756bd0d08a080 to your computer and use it in GitHub Desktop.
Save ollytheninja/c5533d74f59991dfd23756bd0d08a080 to your computer and use it in GitHub Desktop.
Find the Auditor role and account name for an account ID, assume it and print EC2 instances
aws ec2 describe-instances | jq '.Reservations[].Instances[] | {InstanceId,KeyName,Tags,SecurityGroups}'
foreach ACCOUNT (1234567890 0987654321)
ROLE=$(cat ~/.aws/config | grep -B 3 $ACCOUNT | grep Auditor | sed -e 's/.* \(.*\)./\1/g')
echo $ROLE
assume $ROLE
aws ec2 describe-instances | jq '.Reservations[].Instances[] | {InstanceId,KeyName,Tags,SecurityGroups}'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment