1
0
Fork 0
mirror of synced 2025-04-05 14:13:37 +03:00

use python dictionary to store AMI info instead of using conditioning

This commit is contained in:
Scottpedia 2021-03-20 01:14:59 -04:00
parent c7992885ad
commit 968868c2f5

View file

@ -651,21 +651,15 @@
" regionName = event['ResourceProperties']['Region']",
" distribution = event['ResourceProperties']['Distribution']",
" ec2 = boto3.client('ec2',regionName)",
" AMIName = ''",
" if distribution == 'Ubuntu1604':",
" AMIName = 'ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*'",
" elif distribution == 'Ubuntu1804':",
" AMIName = 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*'",
" elif distribution == 'Ubuntu2004':",
" AMIName = 'ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*'",
" elif distribution == 'Debian9':",
" AMIName = 'debian-stretch-hvm-x86_64-gp2-*'",
" elif distribution == 'CentOS7':",
" AMIName = 'CentOS 7.9.2009 x86_64'",
" elif distribution == 'CentOS8':",
" AMIName = 'CentOS 8.3.2011 x86_64'",
" elif distribution == 'AmazonLinux2':",
" AMIName = 'amzn2-ami-hvm-*.*-x86_64-gp2'",
" AMIName = {",
" 'Ubuntu1604': 'ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*',",
" 'Ubuntu1804': 'ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*',",
" 'Ubuntu2004': 'ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*',",
" 'Debian9': 'debian-stretch-hvm-x86_64-gp2-*',",
" 'CentOS7': 'CentOS 7.9.2009 x86_64',",
" 'CentOS8': 'CentOS 8.3.2011 x86_64',",
" 'AmazonLinux2': 'amzn2-ami-hvm-*.*-x86_64-gp2',",
" }[distribution]",
" response = ec2.describe_images(Filters=[{'Name':'name', 'Values':[AMIName]}], Owners=['099720109477', '379101102735', '125523088429', 'amazon'])",
" images = response['Images']",
" images.sort(key=creation_date,reverse=True)",