[PYTHON] List AWS ami

List AWS AMIs.

! /usr/bin/env python
-*- coding: utf-8 -*-
import urllib2
import argparse
from BeautifulSoup import BeautifulSoup

def main():
    fp = urllib2.urlopen('http://cloud-images.ubuntu.com/precise/current/')
    soup = BeautifulSoup(fp)
    table = soup.find('table')
    rows = table.findAll('tr')
    for row in rows[1:]: # first is header
        tds = row.findAll('td')
        region = tds[0].text
        arch = tds[1].text
        store = tds[2].text
        ami = tds[3].text.replace('Launch', '')
        print('{} {} {} {}'.format(region, arch, store, ami))
if __name__ == '__main__':
    main()

Recommended Posts

List AWS ami
List comprehension
linked list
Join list
List comprehension
[Python] list
Get the latest AMI information with the AWS CLI
Creating an AWS EC2 EC2 Instance (Amazon Linux AMI) 2
List the AMIs used by AWS Data Pipeline