parent
b28888f1ae
commit
e06063dc0a
1 changed files with 27 additions and 0 deletions
@ -0,0 +1,27 @@ |
||||
#!/bin/bash |
||||
# I use an "Admin" profile that has all EC2 permissions |
||||
AWSPROFILE="Admin" |
||||
KEYFILE="/Users/USERNAME/.ssh/id_rsa.pub" |
||||
|
||||
# 1. check key file |
||||
if [ ! -f "${KEYFILE}" ] |
||||
then |
||||
echo "${KEYFILE} not found" |
||||
exit 1 |
||||
fi |
||||
KEYNAME=$(basename ${KEYFILE}) |
||||
KEYNAME="${KEYNAME%.pub}" |
||||
|
||||
# 2. use ec2 describe-regions to list available regions |
||||
REGIONS=$(aws ec2 describe-regions | jq -r '.Regions[].RegionName') |
||||
|
||||
# 3. Upload the key file to all the regions |
||||
for reg in $REGIONS |
||||
do |
||||
echo -n "${reg}: " |
||||
aws ec2 import-key-pair --profile "${AWSPROFILE}" \ |
||||
--region ${reg} --key-name ${KEYNAME} \ |
||||
--no-cli-pager --output text \ |
||||
--public-key-material "fileb://${KEYFILE}" |
||||
done |
||||
|
Loading…
Reference in new issue