Skip to content

Instantly share code, notes, and snippets.

@siroken3
Last active December 14, 2015 06:59
Show Gist options
  • Select an option

  • Save siroken3/5047587 to your computer and use it in GitHub Desktop.

Select an option

Save siroken3/5047587 to your computer and use it in GitHub Desktop.
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html にある AKIを取得するための botocore スクリプト
def get_aki(region, architecture="x86_64", partitioned=True):
import botocore.session
session = botocore.session.get_session()
ec2 = session.get_service('ec2')
op = ec2.get_operation('DescribeImages')
code, data = op.call(
ec2.get_endpoint(region),
filters=[
{"name":"owner-alias", "values":["amazon"]},
{"name":"image-type", "values":["kernel"]},
{"name":"architecture", "values":[architecture]}
]
)
images = data['imagesSet']
suffix = '-hd00_' if partitioned else '-hd0_'
last_one_location = sorted([im['imageLocation'] for im in images if im['imageLocation'].find('pv-grub{suffix}'.format(suffix=suffix)) != -1])[-1:][0]
aki = [im['imageId'] for im in images if im['imageLocation'] == last_one_location][0]
return aki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment