Skip to content

Instantly share code, notes, and snippets.

@AlecTaylor
Last active January 26, 2016 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlecTaylor/ef0e51f8b2aa13d987db to your computer and use it in GitHub Desktop.
Save AlecTaylor/ef0e51f8b2aa13d987db to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib2
def get_ubuntu_ami(region='ap-southeast-2', arch='64-bit', root_store='ebs', codename='trusty', version='current'):
# Just a quick hack!
s = urllib2.urlopen(
'http://cloud-images.ubuntu.com/{codename}/{version}/'.format(codename=codename, version=version)
).read().replace(' ', '')
find = '''<tr>
<td><p>{region}</p></td>
<td><p>{arch}</p></td>
<td><p>{root_store}</p></td>
<td><p><buttontype="button"onClick="parent.location='https://console.aws.amazon.com/ec2/home?region={region}#launchAmi=
'''.format(region=region, arch=arch, root_store=root_store).rstrip()
return (lambda first: s[first + len(find):s.find("'", first + len(find))])(s.find(find))
if __name__ == '__main__':
print latest_ubuntu_ami_hack()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment