Question: Python Script to Get Ubuntu 16.04 Image Ids Download the script at https://gist.github.com/drpventura/f20aa74e171c4eee047b90f592ae6110 (Links to an external site.)Links to an external site. and rename it
Python Script to Get Ubuntu 16.04 Image Ids
Download the script at https://gist.github.com/drpventura/f20aa74e171c4eee047b90f592ae6110 (Links to an external site.)Links to an external site. and rename it to list_ubuntu_amis.py. Then modify the code in list_ubuntu_amis.py to extract the Ubuntu 16.04 image ids from AWS using boto3 and display them in the same format.
script from link:
| """ | |
| List the Amazon Linux AMI ids for each region | |
| """ | |
| import boto3 | |
| from pprint import pprint | |
| ec2 = boto3.client('ec2') | |
| resp = ec2.describe_regions() | |
| region_names = sorted([region['RegionName'] for region in resp['Regions']]) | |
| filters = [{'Name': 'architecture', | |
| 'Values': ['x86_64']}, | |
| {'Name': 'virtualization-type', | |
| 'Values': ['hvm']}, | |
| {'Name': 'name', | |
| 'Values': ['amzn-ami-hvm-2017.09.0*-gp2']}] | |
| for region in region_names: | |
| ec2 = boto3.client('ec2', region) | |
| resp = ec2.describe_images(Filters=filters) | |
| # print() | |
| print(' ' + region + ':') | |
| print(' AMI: ' + resp['Images'][0]['ImageId']) | |
| # pprint(resp['Images']) | |
| #pprint(ec2.describe_images(Filters=[{'Name': 'image-id', 'Values': ['ami-8c1be5f6']}])) |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
