You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
699 B
27 lines
699 B
#!/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 |
|
|
|
|