From 1c1305e7e001b2d60726ed3f4ac1ff573f744863 Mon Sep 17 00:00:00 2001 From: Scottpedia Date: Tue, 19 Jan 2021 01:51:53 -0500 Subject: [PATCH] Simplify python script in AWS template --- aws/cloudformation-template-ipsec.json | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/aws/cloudformation-template-ipsec.json b/aws/cloudformation-template-ipsec.json index a911ef8..fdf3a8e 100644 --- a/aws/cloudformation-template-ipsec.json +++ b/aws/cloudformation-template-ipsec.json @@ -658,21 +658,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)",