EC2 API操作

查看 ec2 标签

import boto.ec2
conn=boto.ec2.connect_to_region(eu-west-1)
reservations = conn.get_all_instances()
for res in reservations:
    for inst in res.instances:
        if 'Name' in inst.tags:
            print %s (%s) [%s] % (inst.tags['Name'], inst.id, inst.state)
        else:
            print %s [%s] % (inst.id, inst.state)


根据 Tag 查询实例

from boto import ec2

ec2_conn = ec2.connect_to_region(ap-southeast-1, **test_enviroment_args)
instances = ec2_conn.get_all_instances(filters={tag:Name: Test*})


filter 的具体内容可以参考:参考链接