Created
June 22, 2012 17:12
-
-
Save siroken3/2974030 to your computer and use it in GitHub Desktop.
botoを使って自身のinstanceのタグを得る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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