-
Notifications
You must be signed in to change notification settings - Fork 1
/
ami-public.sh
executable file
·29 lines (24 loc) · 1.22 KB
/
ami-public.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# Params : <profile> <family> <date> <region1> <region2> <region3>...
set -e
# set AWS_PROFILE
export AWS_PROFILE=$1
# List of regions where the amis will be made public
regions=("${@:4}")
# Copying both AMI's to each of the secified regions
for r in ${regions[@]}; do
ami_amd=$(AWS_REGION=$r aws ec2 describe-images --owners self --filters "Name=name,Values=marlin/oyster/worker-$2-amd64-$3" --no-paginate --query 'Images[0].ImageId' --output text)
ami_arm=$(AWS_REGION=$r aws ec2 describe-images --owners self --filters "Name=name,Values=marlin/oyster/worker-$2-arm64-$3" --no-paginate --query 'Images[0].ImageId' --output text)
if [[ $ami_amd != null && "$ami_amd" != "None" ]]; then
echo "Making public amd64 image in region $r: $ami_amd"
AWS_REGION=$r aws ec2 modify-image-attribute --image-id $ami_amd --launch-permission "Add=[{Group=all}]"
else
echo "Found no amd64 image in $r"
fi
if [[ $ami_arm != null && "$ami_arm" != "None" ]]; then
echo "Making public arm64 image in region $r: $ami_arm"
AWS_REGION=$r aws ec2 modify-image-attribute --image-id $ami_arm --launch-permission "Add=[{Group=all}]"
else
echo "Found no arm64 image in $r"
fi
done