Ensure all amis are public and available
This commit is contained in:
+38
-12
@@ -135,21 +135,47 @@ aws ec2 modify-image-attribute --region ${region} --profile ${aws_credentials} -
|
||||
|
||||
# http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region
|
||||
# Images are currently created in eu-central-1
|
||||
echo "Copy image to other regions"
|
||||
aws ec2 copy-image --region us-east-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region us-west-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region us-west-2 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region ap-south-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region ap-northeast-2 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region ap-southeast-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region ap-southeast-2 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region ap-northeast-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region eu-west-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
aws ec2 copy-image --region sa-east-1 --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name}
|
||||
echo "Coping image to other regions"
|
||||
ec2_regions=( "us-east-1" "us-west-1" "us-west-2" "ap-south-1" "ap-northeast-2" "ap-southeast-1" "ap-southeast-2" "ap-northeast-1" "eu-west-1" "sa-east-1" )
|
||||
ec2_amis=( )
|
||||
|
||||
for r in ${ec2_regions[@]}; do
|
||||
echo "=> ${r}"
|
||||
ami_id=$(aws ec2 copy-image --region ${r} --profile ${aws_credentials} --source-image-id ${image_id} --source-region ${region} --name ${snapshot_name} | $JSON ImageId)
|
||||
|
||||
# append in the same order as the regions
|
||||
ec2_amis+=( ${ami_id} )
|
||||
done
|
||||
|
||||
# wait for all images to be available
|
||||
echo "Waiting for images to be ready (first will take the longest)..."
|
||||
region_string="${region}=${image_id}"
|
||||
i=0
|
||||
while [ $i -lt ${#ec2_regions[*]} ]; do
|
||||
echo "=> ${ec2_regions[$i]} ${ec2_amis[$i]}"
|
||||
while true; do
|
||||
event_status=`aws ec2 describe-images --region ${ec2_regions[$i]} --profile ${aws_credentials} --image-id ${ec2_amis[$i]} | $JSON Images[0].State`
|
||||
if [[ "${event_status}" == "available" ]]; then
|
||||
break
|
||||
fi
|
||||
debug -n "."
|
||||
sleep 10
|
||||
done
|
||||
|
||||
# now make it public
|
||||
aws ec2 modify-image-attribute --region ${ec2_regions[$i]} --profile ${aws_credentials} --image-id ${ec2_amis[$i]} --launch-permission "{\"Add\":[{\"Group\":\"all\"}]}"
|
||||
|
||||
# append to output string for release tool
|
||||
region_string+=",${ec2_regions[$i]}:${ec2_amis[$i]}"
|
||||
|
||||
# inc the iteration counter
|
||||
i=$(( $i + 1));
|
||||
done
|
||||
|
||||
echo "Done."
|
||||
echo ""
|
||||
echo "--------------------------------------------------"
|
||||
echo "New image id is: ${image_id}"
|
||||
echo "Image region string for release:"
|
||||
echo "${region_string}"
|
||||
echo "--------------------------------------------------"
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user