simplify coding
This commit is contained in:
parent
fdd220b7a3
commit
bc945f5251
1 changed files with 9 additions and 15 deletions
|
@ -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)",
|
||||
|
|
Loading…
Add table
Reference in a new issue