Skip to main content

Posts

Showing posts from March, 2011

boto api on amazon ec2

Here are several examples of boto api on amazon ec2: Connect to a region: conn=boto.ec2.connect_to_region('us-west-1a') Get an instance by id: instance = conn.get_all_instances(['i-xxxxxxxx'])[0].instances[0] Run(create) an instance: conn.run_instances(image_id=u'ami-xxxxxxxx', key_name='default', security_groups=['default-group'],                   instance_type='m2.4xlarge', placement='us-west-1a') Add/remove a tag for an instance: instance.add_tag('Name','default') instance.remove_tag('Name') Reboot an instance: instance.reboot() Terminate an instance: instance.terminate() Get an ebs volume by id: volume = conn.get_all_volumes(['vol-xxxxxxxx'])[0] Attach an ebs volume to an instance: volume.attach(instance.id, '/etc/sdh') conn.attach_volume(volume.id, instance.id, '/dev/sdh')