Created
December 10, 2021 09:58
-
-
Save dongsupark/bf5ad50279d4789050ec9a6f29ad0882 to your computer and use it in GitHub Desktop.
make AMIs public in all AWS regions
This file contains 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 | |
# Run with a filter for image names like: | |
# | |
# ./make-amis-public.sh capa-ami-flatcar* | |
# | |
if [ -z "$1" ] ; then | |
echo "Please pass the name of the AMI" | |
exit 1 | |
fi | |
IMAGE_FILTER="${1}" | |
declare -a REGIONS=($(aws ec2 describe-regions --output json | jq -r '[.Regions[].RegionName] | join(" ")')) | |
for REGION in "${REGIONS[@]}" ; do | |
AMI_IDS=$(aws ec2 describe-images --query 'Images[*].[ImageId]' --filters "Name=name,Values=${IMAGE_FILTER}" --region "${REGION}" --output text) | |
for AMI_ID in ${AMI_IDS}; do | |
echo "region ${REGION}: making public AMI ${AMI_ID} ..." | |
aws ec2 modify-image-attribute --region "${REGION}" --image-id "${AMI_ID}" \ | |
--launch-permission "Add=[{Group=all}]" | |
echo "image attributes of AMI ${AMI_ID} ..." | |
aws ec2 describe-image-attribute --region "${REGION}" --image-id "${AMI_ID}" \ | |
--attribute launchPermission | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment