-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
upload-ami/src/upload_ami/request_public_ami_quota_increase.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import boto3 | ||
import logging | ||
|
||
|
||
def get_public_ami_service_quota(servicequotas): | ||
pages = servicequotas.get_paginator( | ||
'list_service_quotas').paginate(ServiceCode="ec2") | ||
for page in pages: | ||
for quota in page["Quotas"]: | ||
if quota["QuotaName"] == "Public AMIs": | ||
return quota | ||
raise Exception("No public AMI quota found") | ||
|
||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO) | ||
ec2 = boto3.client("ec2") | ||
regions = ec2.describe_regions()["Regions"] | ||
for region in regions: | ||
servicequotas = boto3.client( | ||
"service-quotas", region_name=region["RegionName"]) | ||
service_quota = get_public_ami_service_quota(servicequotas) | ||
try: | ||
logging.info(f"Requesting quota increase for {region['RegionName']}") | ||
servicequotas.request_service_quota_increase( | ||
ServiceCode="ec2", | ||
QuotaCode=service_quota['QuotaCode'], | ||
DesiredValue=100, | ||
) | ||
except Exception as e: | ||
logging.warn(e) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |