Last active
May 4, 2023 20:54
-
-
Save gene1wood/56e42097e0f0ac1aace14cbc41ee3e11 to your computer and use it in GitHub Desktop.
AWS CloudFormation CentOS 6 7 8 and 8 Stream AMIs
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
Mappings: | |
RegionMap: | |
ap-northeast-1: | |
CentOS6x8664EBSHVM: ami-021b97cd4c0816008 | |
ap-northeast-2: | |
CentOS6x8664EBSHVM: ami-0565df27c8c43e2fb | |
ap-northeast-3: | |
CentOS6x8664EBSHVM: ami-09af14a7a3b503647 | |
ap-south-1: | |
CentOS6x8664EBSHVM: ami-0d45bbf6fbf4d9081 | |
ap-southeast-1: | |
CentOS6x8664EBSHVM: ami-009b8ca21a4336165 | |
ap-southeast-2: | |
CentOS6x8664EBSHVM: ami-02fd1d1178c6b0963 | |
ca-central-1: | |
CentOS6x8664EBSHVM: ami-0f88110fb06eeb78d | |
eu-central-1: | |
CentOS6x8664EBSHVM: ami-0d30ba8805fc37fea | |
eu-north-1: | |
CentOS6x8664EBSHVM: ami-077680d76be2be30c | |
eu-west-1: | |
CentOS6x8664EBSHVM: ami-07c6c959dd5979f64 | |
eu-west-2: | |
CentOS6x8664EBSHVM: ami-04a0cf26602524882 | |
eu-west-3: | |
CentOS6x8664EBSHVM: ami-069c2df047f2c7f74 | |
sa-east-1: | |
CentOS6x8664EBSHVM: ami-0f25cb297cb935d0c | |
us-east-1: | |
CentOS6x8664EBSHVM: ami-0383c829642a98d40 | |
us-east-2: | |
CentOS6x8664EBSHVM: ami-0c624332b9bf0f506 | |
us-west-1: | |
CentOS6x8664EBSHVM: ami-0d282a216ae4c0c42 | |
us-west-2: | |
CentOS6x8664EBSHVM: ami-0e025868cef8764d8 |
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
Mappings: | |
RegionMap: | |
ap-northeast-1: | |
CentOS7x8664EBSHVM: ami-08c8b8667ebcacaa6 | |
ap-northeast-2: | |
CentOS7x8664EBSHVM: ami-0d26352ab37619e7b | |
ap-northeast-3: | |
CentOS7x8664EBSHVM: ami-04783ead0741db62a | |
ap-south-1: | |
CentOS7x8664EBSHVM: ami-04c84f136b3c9d872 | |
ap-southeast-1: | |
CentOS7x8664EBSHVM: ami-0b6e567c5d6571739 | |
ap-southeast-2: | |
CentOS7x8664EBSHVM: ami-043e476ddb8635c3b | |
ca-central-1: | |
CentOS7x8664EBSHVM: ami-05555f3106026cbf4 | |
eu-central-1: | |
CentOS7x8664EBSHVM: ami-0c239ecd40dcc174c | |
eu-north-1: | |
CentOS7x8664EBSHVM: ami-0d1ff703c259471e9 | |
eu-west-1: | |
CentOS7x8664EBSHVM: ami-05a178e6f938f2c39 | |
eu-west-2: | |
CentOS7x8664EBSHVM: ami-0bab5c8be0975423b | |
eu-west-3: | |
CentOS7x8664EBSHVM: ami-0359e47f84edf87e7 | |
sa-east-1: | |
CentOS7x8664EBSHVM: ami-074d4dd5abaaaaf43 | |
us-east-1: | |
CentOS7x8664EBSHVM: ami-011939b19c6bd1492 | |
us-east-2: | |
CentOS7x8664EBSHVM: ami-02cae3195fa1622a8 | |
us-west-1: | |
CentOS7x8664EBSHVM: ami-00008506813cea27a | |
us-west-2: | |
CentOS7x8664EBSHVM: ami-0a4497cbe959da512 |
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
Mappings: | |
RegionMap: | |
ap-northeast-1: | |
CentOS8x8664EBSHVM: ami-00f65b9dfc6773444 | |
ap-northeast-2: | |
CentOS8x8664EBSHVM: ami-021d0f6d9b3209c3b | |
ap-northeast-3: | |
CentOS8x8664EBSHVM: ami-042d3d5e10ad44a53 | |
ap-south-1: | |
CentOS8x8664EBSHVM: ami-0e6837d3d816a2ac6 | |
ap-southeast-1: | |
CentOS8x8664EBSHVM: ami-06f055d0ae93b05be | |
ap-southeast-2: | |
CentOS8x8664EBSHVM: ami-04ae481a2373f6348 | |
ca-central-1: | |
CentOS8x8664EBSHVM: ami-0949556ba850896ed | |
eu-central-1: | |
CentOS8x8664EBSHVM: ami-04c21037b3f953d37 | |
eu-north-1: | |
CentOS8x8664EBSHVM: ami-0966447150c11d877 | |
eu-west-1: | |
CentOS8x8664EBSHVM: ami-0426e00f13491b715 | |
eu-west-2: | |
CentOS8x8664EBSHVM: ami-08095fbc7037048f3 | |
eu-west-3: | |
CentOS8x8664EBSHVM: ami-0a314e339048febf5 | |
sa-east-1: | |
CentOS8x8664EBSHVM: ami-0002f659237250f6e | |
us-east-1: | |
CentOS8x8664EBSHVM: ami-0d6e9a57f6259ba3a | |
us-east-2: | |
CentOS8x8664EBSHVM: ami-01d5ac8f5f8804300 | |
us-west-1: | |
CentOS8x8664EBSHVM: ami-08b547f0dcb46c4d3 | |
us-west-2: | |
CentOS8x8664EBSHVM: ami-0c9ff37f7a65a36a2 |
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
{ | |
"Mappings": { | |
"RegionMap": { | |
"ap-northeast-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-09d601e0cf25901b0" | |
}, | |
"ap-northeast-2": { | |
"CentOS8Streamx8664EBSHVM": "ami-07de343a1f1f28c13" | |
}, | |
"ap-northeast-3": {}, | |
"ap-south-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-0b7b39ff51f3dad24" | |
}, | |
"ap-southeast-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-04bc8877d84c7b0f0" | |
}, | |
"ap-southeast-2": { | |
"CentOS8Streamx8664EBSHVM": "ami-07c93ed8c0fd61a22" | |
}, | |
"ca-central-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-0b2ea49c80f5eea36" | |
}, | |
"eu-central-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-00c7d8758693386f9" | |
}, | |
"eu-north-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-0ba80a09a6f5d7c9d" | |
}, | |
"eu-west-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-03558b9c50f008efb" | |
}, | |
"eu-west-2": { | |
"CentOS8Streamx8664EBSHVM": "ami-00c860ed641e6ff27" | |
}, | |
"eu-west-3": { | |
"CentOS8Streamx8664EBSHVM": "ami-07f074dc2ecbc769b" | |
}, | |
"sa-east-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-02ab2f892d2637083" | |
}, | |
"us-east-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-0add55cf997006f64" | |
}, | |
"us-east-2": { | |
"CentOS8Streamx8664EBSHVM": "ami-0ffbdee6ae3169e6c" | |
}, | |
"us-west-1": { | |
"CentOS8Streamx8664EBSHVM": "ami-09840074796149b18" | |
}, | |
"us-west-2": { | |
"CentOS8Streamx8664EBSHVM": "ami-068a090f464518265" | |
} | |
} | |
} | |
} |
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
Mappings: | |
RegionMap: | |
ap-northeast-1: | |
CentOS8Streamx8664EBSHVM: ami-09d601e0cf25901b0 | |
ap-northeast-2: | |
CentOS8Streamx8664EBSHVM: ami-07de343a1f1f28c13 | |
ap-northeast-3: {} | |
ap-south-1: | |
CentOS8Streamx8664EBSHVM: ami-0b7b39ff51f3dad24 | |
ap-southeast-1: | |
CentOS8Streamx8664EBSHVM: ami-04bc8877d84c7b0f0 | |
ap-southeast-2: | |
CentOS8Streamx8664EBSHVM: ami-07c93ed8c0fd61a22 | |
ca-central-1: | |
CentOS8Streamx8664EBSHVM: ami-0b2ea49c80f5eea36 | |
eu-central-1: | |
CentOS8Streamx8664EBSHVM: ami-00c7d8758693386f9 | |
eu-north-1: | |
CentOS8Streamx8664EBSHVM: ami-0ba80a09a6f5d7c9d | |
eu-west-1: | |
CentOS8Streamx8664EBSHVM: ami-03558b9c50f008efb | |
eu-west-2: | |
CentOS8Streamx8664EBSHVM: ami-00c860ed641e6ff27 | |
eu-west-3: | |
CentOS8Streamx8664EBSHVM: ami-07f074dc2ecbc769b | |
sa-east-1: | |
CentOS8Streamx8664EBSHVM: ami-02ab2f892d2637083 | |
us-east-1: | |
CentOS8Streamx8664EBSHVM: ami-0add55cf997006f64 | |
us-east-2: | |
CentOS8Streamx8664EBSHVM: ami-0ffbdee6ae3169e6c | |
us-west-1: | |
CentOS8Streamx8664EBSHVM: ami-09840074796149b18 | |
us-west-2: | |
CentOS8Streamx8664EBSHVM: ami-068a090f464518265 |
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
import boto3 | |
import dateutil.parser | |
import json | |
import yaml | |
OS_VERSION = "CentOS 8 Stream" | |
# OS_VERSION = "CentOS 8" | |
# OS_VERSION = "CentOS 7" | |
# OS_VERSION = "CentOS 6" | |
OUTPUT_SYNTAX = 'both' | |
# https://wiki.centos.org/Cloud/AWS#AWS_Provided_Marketplace_Images_with_Updates | |
CENTOSORG_CENTOS_8_PRODUCT_CODE = "47k9ia2igxpcce2bzo8u3kj03" | |
CENTOSORG_CENTOS_7_PRODUCT_CODE = "cvugziknvmxgqna9noibqnnsy" | |
CENTOSORG_CENTOS_6_PRODUCT_CODE = "ckx0h8ljio731afm2k92jtg62" | |
CENTOS_8_NAME_PREFIX = "CentOS Stream 8 x86_64" | |
REDHAT_COMMUNITY_PLATFORM_ENGINEERING_AWS_ACCOUNT_ID = "125523088429" | |
def get_images_by_product_code(product_code): | |
images = [] | |
for region_name in region_list: | |
client = boto3.client('ec2', region_name=region_name) | |
response = client.describe_images(Owners=['aws-marketplace'], Filters=[{'Name': 'product-code','Values': [product_code]}]) | |
for image in response['Images']: | |
image[u'Region'] = region_name | |
images.append(image) | |
return images | |
def get_images_by_owner(owner_id, image_name_prefix): | |
images = [] | |
for region_name in region_list: | |
client = boto3.client('ec2', region_name=region_name) | |
response = client.describe_images(Owners=[owner_id]) | |
for image in response['Images']: | |
if image['Name'].startswith(image_name_prefix): | |
image[u'Region'] = region_name | |
images.append(image) | |
return images | |
client = boto3.client('ec2') | |
response = client.describe_regions() | |
region_list = [x['RegionName'] for x in response['Regions']] | |
RegionMap = {} | |
for region in region_list: | |
RegionMap[region] = {} | |
if OS_VERSION == "CentOS 8 Stream": | |
images = get_images_by_owner(REDHAT_COMMUNITY_PLATFORM_ENGINEERING_AWS_ACCOUNT_ID, CENTOS_8_NAME_PREFIX) | |
CLOUDFORMATION_TEMPLATE_VAR_NAME = "CentOS8Streamx8664EBSHVM" | |
elif OS_VERSION == "CentOS 8": | |
images = get_images_by_product_code(CENTOSORG_CENTOS_8_PRODUCT_CODE) | |
CLOUDFORMATION_TEMPLATE_VAR_NAME = "CentOS8x8664EBSHVM" | |
elif OS_VERSION == "CentOS 7": | |
images = get_images_by_product_code(CENTOSORG_CENTOS_7_PRODUCT_CODE) | |
CLOUDFORMATION_TEMPLATE_VAR_NAME = "CentOS7x8664EBSHVM" | |
elif OS_VERSION == "CentOS 6": | |
images = get_images_by_product_code(CENTOSORG_CENTOS_6_PRODUCT_CODE) | |
CLOUDFORMATION_TEMPLATE_VAR_NAME = "CentOS6x8664EBSHVM" | |
else: | |
images = [] | |
CLOUDFORMATION_TEMPLATE_VAR_NAME = "none" | |
for region in region_list: | |
regional_ami_list = [x for x in images if x['Region'] == region] | |
if len(regional_ami_list) == 0: | |
continue | |
regional_ami_list.sort( | |
reverse=True, | |
key=lambda x: dateutil.parser.parse(x['CreationDate'])) | |
newest_ami = regional_ami_list[0] | |
RegionMap[region][CLOUDFORMATION_TEMPLATE_VAR_NAME] = newest_ami[u'ImageId'] | |
if OUTPUT_SYNTAX in ['json', 'both']: | |
print(json.dumps({"Mappings": {"RegionMap": RegionMap}}, | |
sort_keys=True, | |
indent=2, | |
separators=(',', ': '))) | |
if OUTPUT_SYNTAX in ['yaml', 'both']: | |
print(yaml.safe_dump( | |
{"Mappings": {"RegionMap": RegionMap}}, default_flow_style=False)) |
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
#!/bin/bash | |
for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do echo "$region $(aws --region $region ec2 describe-images --owners 125523088429 --query 'Images[?starts_with(Name, `CentOS Stream 8 x86_64`) == `true`].[ImageId,Name,CreationDate]|reverse(sort_by(@,&[2]))[0:1]' --output text)"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment