1010# The script can be run with normal OS user privileges.
1111# The script is not supposed to modify anything.
1212# There is no warranty. Please check the script upfront. You will use it on your own risk
13+
1314# String to be used when no AMI is available in region
1415NOAMI=" NOT_SUPPORTED"
15- # Change your aws prfile if needed here:
16- PROFILE=" --profile default"
16+
17+ # Change your aws profile if needed here (example, " --profile default"):
18+ PROFILE=${DLE_AWS_PROFILE:- " " }
19+
20+ DLE_CF_TEMPLATE_FILE=" ${DLE_CF_TEMPLATE_FILE:- dle_cf.yaml} "
21+
1722# Check whether AWS CLI is installed and in search path
1823if ! aws_loc=" $( type -p " aws" ) " || [ -z " $aws_loc " ]; then
19- echo " Error: Script requeres AWS CLI . Install it and retry"
24+ echo " Error: Script requires AWS CLI . Install it and retry"
2025exit 1
2126fi
27+
2228# Check whether parameter has been provided
2329if [ -z " $1 " ]
2430then
@@ -29,14 +35,22 @@ NAME=$1
2935fi
3036echo " Will search for AMIs with name: ${NAME} "
3137echo " ---------------------------------------"
38+
39+ # Clean AWSRegionArch2AMI list
40+ yq e -i ' del( .Mappings.AWSRegionArch2AMI )' ${DLE_CF_TEMPLATE_FILE}
41+
3242# #NAME=DBLABserver*
33- R=$( aws ec2 describe-regions --query " Regions[].{Name:RegionName}" --output text ${PROFILE} )
34- for i in $R ; do
35- AMI=` aws ec2 describe-images --owners 005923036815 --region $i --filters " Name=name,Values=${NAME} " --output json | jq -r ' .Images | sort_by(.CreationDate) | last(.[]).ImageId' `
36- if [ -z " $AMI " ]
37- then
38- AMI=$NOAMI
39- fi
40- echo " " ${i} : $' \n ' " " HVM64: ${AMI}
43+ Regions=$( aws ec2 describe-regions --query " Regions[].{Name:RegionName}" --output text ${PROFILE} )
44+ for i in $Regions ; do
45+ AMI=` aws ec2 describe-images --owners 005923036815 --region $i --filters " Name=name,Values=${NAME} " --output json | jq -r ' .Images | sort_by(.CreationDate) | last(.[]).ImageId' `
46+ if [ -z " $AMI " ]; then
47+ AMI=$NOAMI
48+ fi
49+
50+ echo " " ${i} : $' \n ' " " HVM64: ${AMI}
51+
52+ if [ " $AMI " != " $NOAMI " ]; then
53+ yq e -i " .Mappings.AWSRegionArch2AMI.\" ${i} \" = {\" HVM64\" : \" ${AMI} \" }" ${DLE_CF_TEMPLATE_FILE}
54+ fi
4155done
4256
0 commit comments