Skip to content

Instantly share code, notes, and snippets.

@cynicXer
Created July 14, 2017 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cynicXer/638be8a13fe2b361564eb2abb7529e87 to your computer and use it in GitHub Desktop.
Save cynicXer/638be8a13fe2b361564eb2abb7529e87 to your computer and use it in GitHub Desktop.
More AWS Bash Stuffs
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region | jq '.Reservations[] | ( .Instances[] | {state: .State.Name, name: .KeyName, type: .InstanceType, key: .KeyName})'
done
keypair=$USER # or some name that is meaningful to you
publickeyfile=$HOME/.ssh/id_rsa.pub
regions=$(aws ec2 describe-regions \
--output text \
--query 'Regions[*].RegionName')
for region in $regions; do
echo $region
aws ec2 import-key-pair \
--region "$region" \
--key-name "$keypair" \
--public-key-material "file://$publickeyfile"
done
keypair=$USER # or some name that is meaningful to you
publickeyfile=$HOME/.ssh/id_rsa.pub
regions=$(aws ec2 describe-regions \
--output text \
--query 'Regions[*].RegionName')
for region in $regions;
echo $region
aws ec2 delete-key-pair \
--region "$region" \
--key-name "$keypair" \
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment