Skip to content

Instantly share code, notes, and snippets.

@siroken3
Created June 22, 2012 17:12
Show Gist options
  • Save siroken3/2974030 to your computer and use it in GitHub Desktop.
Save siroken3/2974030 to your computer and use it in GitHub Desktop.
botoを使って自身のinstanceのタグを得る
#! /user/bin/env python
from subprocess import check_cal
import urllib2
import boto.ec2
f = urllib2.urlopen('http://169.254.169.254/latest/meta-data/instance-id')
id = f.readline()
region = boto.ec2.get_region('us-west-2')
conn = region.connect()
instance = conn.get_all_instances(instance_ids=[id])[0].instances[0]
name = instance.tags['Name']
check_call(["hostname",name])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment