adhoc script to fix aws publicAMI quotas for all regions

This commit is contained in:
Neil Hanlon 2023-01-18 17:39:00 -05:00
parent bedefe7af0
commit 42b054ac5b
Signed by: neil
GPG Key ID: 705BC21EC3C70F34
1 changed files with 68 additions and 0 deletions

mangle/ Normal file
View File

@ -0,0 +1,68 @@
# Source common variables
# shellcheck disable=SC2046,1091,1090
source "$(dirname "${BASH_SOURCE[0]}")/common"
usage() {
echo "usage: $0"
aws() {
# shellcheck disable=SC2068
command aws --profile resf-ami --output json $@
# Get the quota code for Public AMIs once
quota_code=$(aws service-quotas list-service-quotas --service-code ec2 --region us-east-1 --query "Quotas[*].{QuotaCode:QuotaCode,QuotaName:QuotaName}" | jq '.[] | select(.QuotaName == "Public AMIs") | .QuotaCode' | tr -d '"')
function get_current_quota() {
# Get the current value of the quota
current_value=$(aws service-quotas get-service-quota --service-code ec2 --quota-code "$quota_code" --region "$region" 2>/dev/null | jq .Quota.Value 2>/dev/null)
# shellcheck disable=SC2181
if [[ $? -gt 0 ]]; then
echo "ERR"
echo "$current_value"
function request_quota_increase() {
mapfile -t regions <<<"$@"
for region in "${regions[@]}"; do
# Get the current value of the quota
current_value=$(get_current_quota "$region")
if ((current_value >= QUOTA)); then
echo "Quota for Public AMIs in region $region is already set to $current_value, skipping request."
# Request the quota increase
request_output=$(aws service-quotas request-service-quota-increase --service-code ec2 --quota-code "$quota_code" --region "$region" --desired-value "$QUOTA")
request_id=$(echo "$request_output" | jq .RequestedQuota.Id | tr -d '"')
echo "Successfully submitted request with ID: $request_id"
function list_quotas() {
mapfile -t regions <<<"$@"
for region in "${regions[@]}"; do
current_quota=$(get_current_quota "$region")
request_info=$(aws service-quotas list-requested-service-quota-change-history-by-quota --service-code ec2 --quota-code "$quota_code" --region "$region" --query "RequestedQuotas[-1:].{DesiredValue:DesiredValue,Status:Status}" 2>/dev/null)
requested_value=$(echo "$request_info" | jq .[].DesiredValue)
case_status=$(echo "$request_info" | jq .[].Status | tr -d '"')
output="$output\n$region $current_quota $requested_value $case_status"
echo -e "$output" | column -t
REGIONS=$(aws ec2 describe-regions \
--all-regions \
--query "Regions[].{Name:RegionName}" \
--output text)
list_quotas "$REGIONS"
# request_quota_increase "$REGIONS"