Forked from gene1wood/AWS-CentOS-6-7-8-8-Stream-AMIs.md
Created
August 22, 2019 14:42
-
-
Save yiidtw/c9836f61783ee69ce2c3f526bc08f67d to your computer and use it in GitHub Desktop.
AWS CloudFormation CentOS 7 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": { | |
"CentOS7x8664EBSHVM": "ami-045f38c93733dd48d" | |
}, | |
"ap-northeast-2": { | |
"CentOS7x8664EBSHVM": "ami-06cf2a72dadf92410" | |
}, | |
"ap-south-1": { | |
"CentOS7x8664EBSHVM": "ami-02e60be79e78fef21" | |
}, | |
"ap-southeast-1": { | |
"CentOS7x8664EBSHVM": "ami-0b4dd9d65556cac22" | |
}, | |
"ap-southeast-2": { | |
"CentOS7x8664EBSHVM": "ami-08bd00d7713a39e7d" | |
}, | |
"ca-central-1": { | |
"CentOS7x8664EBSHVM": "ami-033e6106180a626d0" | |
}, | |
"eu-central-1": { | |
"CentOS7x8664EBSHVM": "ami-04cf43aca3e6f3de3" | |
}, | |
"eu-north-1": { | |
"CentOS7x8664EBSHVM": "ami-5ee66f20" | |
}, | |
"eu-west-1": { | |
"CentOS7x8664EBSHVM": "ami-0ff760d16d9497662" | |
}, | |
"eu-west-2": { | |
"CentOS7x8664EBSHVM": "ami-0eab3a90fc693af19" | |
}, | |
"eu-west-3": { | |
"CentOS7x8664EBSHVM": "ami-0e1ab783dc9489f34" | |
}, | |
"sa-east-1": { | |
"CentOS7x8664EBSHVM": "ami-0b8d86d4bf91850af" | |
}, | |
"us-east-1": { | |
"CentOS7x8664EBSHVM": "ami-02eac2c0129f6376b" | |
}, | |
"us-east-2": { | |
"CentOS7x8664EBSHVM": "ami-0f2b4fc905b0bd1f1" | |
}, | |
"us-west-1": { | |
"CentOS7x8664EBSHVM": "ami-074e2d6769f445be5" | |
}, | |
"us-west-2": { | |
"CentOS7x8664EBSHVM": "ami-01ed306a12b7d1c96" | |
} | |
} | |
} | |
} |
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-045f38c93733dd48d | |
ap-northeast-2: | |
CentOS7x8664EBSHVM: ami-06cf2a72dadf92410 | |
ap-south-1: | |
CentOS7x8664EBSHVM: ami-02e60be79e78fef21 | |
ap-southeast-1: | |
CentOS7x8664EBSHVM: ami-0b4dd9d65556cac22 | |
ap-southeast-2: | |
CentOS7x8664EBSHVM: ami-08bd00d7713a39e7d | |
ca-central-1: | |
CentOS7x8664EBSHVM: ami-033e6106180a626d0 | |
eu-central-1: | |
CentOS7x8664EBSHVM: ami-04cf43aca3e6f3de3 | |
eu-north-1: | |
CentOS7x8664EBSHVM: ami-5ee66f20 | |
eu-west-1: | |
CentOS7x8664EBSHVM: ami-0ff760d16d9497662 | |
eu-west-2: | |
CentOS7x8664EBSHVM: ami-0eab3a90fc693af19 | |
eu-west-3: | |
CentOS7x8664EBSHVM: ami-0e1ab783dc9489f34 | |
sa-east-1: | |
CentOS7x8664EBSHVM: ami-0b8d86d4bf91850af | |
us-east-1: | |
CentOS7x8664EBSHVM: ami-02eac2c0129f6376b | |
us-east-2: | |
CentOS7x8664EBSHVM: ami-0f2b4fc905b0bd1f1 | |
us-west-1: | |
CentOS7x8664EBSHVM: ami-074e2d6769f445be5 | |
us-west-2: | |
CentOS7x8664EBSHVM: ami-01ed306a12b7d1c96 |
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 | |
client = boto3.client('ec2') | |
response = client.describe_regions() | |
region_list = [x['RegionName'] for x in response['Regions']] | |
# https://wiki.centos.org/Cloud/AWS#head-224024c7b3b083bd574bec6861bcdfd3487a5418 | |
CENTOSORG_CENTOS_7_PRODUCT_CODE = "aw0evgkw8e5c1q413zgy5pjce" | |
CENTOSORG_CENTOS_6_PRODUCT_CODE = "6x5jmcajty9edm3f211pqjfn2" | |
OUTPUT_SYNTAX = 'yaml' | |
amis = [] | |
RegionMap = {} | |
for region in region_list: | |
RegionMap[region] = {} | |
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': [ | |
CENTOSORG_CENTOS_7_PRODUCT_CODE | |
] | |
} | |
] | |
) | |
for image in response['Images']: | |
image[u'Region'] = region_name | |
amis.append(image) | |
for region in region_list: | |
regional_ami_list = [x for x in amis 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]['CentOS7x8664EBSHVM'] = newest_ami[u'ImageId'] | |
if OUTPUT_SYNTAX == 'json': | |
print(json.dumps({"Mappings": {"RegionMap": RegionMap}}, | |
sort_keys=True, | |
indent = 2, | |
separators = (',', ': '))) | |
elif OUTPUT_SYNTAX == 'yaml': | |
print(yaml.safe_dump( | |
{"Mappings": {"RegionMap": RegionMap}}, default_flow_style=False)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment