Created
November 29, 2014 04:28
-
-
Save mdodsworth/afa1f75d55e6a58ef621 to your computer and use it in GitHub Desktop.
script for importing key pairs for all ec2 regions
This file contains hidden or 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
#!/bin/bash | |
# Imports a key across all regions | |
regions=$(aws ec2 describe-regions --output text | cut -f 2 | cut -d . -f 2) | |
OPTIND=1 | |
usage() { | |
cat << EOF >&2 | |
usage: $0 -k <key name> -f <public key> | |
EOF | |
} | |
while getopts "k:f:" arg; do | |
case $arg in | |
k) | |
keyname=$OPTARG | |
;; | |
f) | |
filename=$OPTARG | |
;; | |
\?) | |
usage | |
exit 1 | |
;; | |
esac | |
done | |
if [[ -z $keyname ]] || [[ -z $filename ]]; then | |
usage | |
exit 1 | |
fi | |
for region in $regions; do | |
aws ec2 import-key-pair --key-name $keyname --public-key-material file://$filename --region $region | |
done | |
shift $((OPTIND-1)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment