EC2

boto.ec2

This module provides an interface to the Elastic Compute Cloud (EC2) service from AWS.

boto.ec2.connect_to_region(region_name, **kw_params)
boto.ec2.get_region(region_name, **kw_params)
boto.ec2.regions(**kw_params)

Get all available regions for the EC2 service. You may pass any of the arguments accepted by the EC2Connection object’s constructor as keyword arguments and they will be passed along to the EC2Connection object.

Return type:list
Returns:A list of boto.ec2.regioninfo.RegionInfo

boto.ec2.address

Represents an EC2 Elastic IP Address

class boto.ec2.address.Address(connection=None, public_ip=None, instance_id=None)
associate(instance_id)
delete()
disassociate()
endElement(name, value, connection)
release()

boto.ec2.autoscale

This module provides an interface to the Elastic Compute Cloud (EC2) Auto Scaling service.

class boto.ec2.autoscale.AutoScaleConnection(aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, host='autoscaling.amazonaws.com', debug=1, https_connection_factory=None, region=None, path='/')
build_list_params(params, items, label)
items is a list of dictionaries or strings:
[{‘Protocol’ : ‘HTTP’,
‘LoadBalancerPort’ : ‘80’, ‘InstancePort’ : ‘80’},..] etc.
or
[‘us-east-1b’,...]
create_auto_scaling_group(as_group)
Create auto scaling group.
create_launch_configuration(launch_config)

Creates a new Launch Configuration.

Parameter:launch_config (boto.ec2.autoscale.launchconfig.LaunchConfiguration) – LaunchConfiguraiton object.
create_trigger(trigger)
get_all_activities(autoscale_group, activity_ids=None, max_records=100)

Get all activities for the given autoscaling group.

Parameter:autoscale_group (str or AutoScalingGroup object) – The auto scaling group to get activities on.

@max_records: int :param max_records: Maximum amount of activities to return.

get_all_groups(names=None)
get_all_launch_configurations(names=None)
get_all_triggers(autoscale_group)
terminate_instance(instance_id, decrement_capacity=True)

boto.ec2.autoscale.activity

class boto.ec2.autoscale.activity.Activity(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.autoscale.group

class boto.ec2.autoscale.group.AutoScalingGroup(connection=None, group_name=None, availability_zone=None, launch_config=None, availability_zones=None, load_balancers=None, cooldown=0, min_size=None, max_size=None)
delete()
Delete this auto-scaling group.
endElement(name, value, connection)
get_activities(activity_ids=None, max_records=100)
Get all activies for this group.
get_all_triggers()
Get all triggers for this auto scaling group.
set_capacity(capacity)
Set the desired capacity for the group.
shutdown_instances()
Convenience method which shuts down all instances associated with this group.
startElement(name, attrs, connection)
update()
Sync local changes with AutoScaling group.
class boto.ec2.autoscale.group.Instance(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.autoscale.instance

class boto.ec2.autoscale.instance.Instance(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
terminate()
Terminate this instance.

boto.ec2.autoscale.launchconfig

class boto.ec2.autoscale.launchconfig.LaunchConfiguration(connection=None, name=None, image_id=None, key_name=None, security_groups=None, user_data=None, instance_type='m1.small', kernel_id=None, ramdisk_id=None, block_device_mappings=None)
delete()
Delete this launch configuration.
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.autoscale.request

class boto.ec2.autoscale.request.Request(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.autoscale.trigger

class boto.ec2.autoscale.trigger.Trigger(connection=None, name=None, autoscale_group=None, dimensions=None, measure_name=None, statistic=None, unit=None, period=60, lower_threshold=None, lower_breach_scale_increment=None, upper_threshold=None, upper_breach_scale_increment=None, breach_duration=None)

An auto scaling trigger.

delete()
Delete this trigger.
endElement(name, value, connection)
startElement(name, attrs, connection)
update()
Write out differences to trigger.

boto.ec2.buyreservation

class boto.ec2.buyreservation.BuyReservation
get(params)
get_instance_type(params)
get_quantity(params)
get_region(params)
get_zone(params)

boto.ec2.cloudwatch

This module provides an interface to the Elastic Compute Cloud (EC2) CloudWatch service from AWS.

The 5 Minute How-To Guide

First, make sure you have something to monitor. You can either create a LoadBalancer or enable monitoring on an existing EC2 instance. To enable monitoring, you can either call the monitor_instance method on the EC2Connection object or call the monitor method on the Instance object.

It takes a while for the monitoring data to start accumulating but once it does, you can do this:

>>> import boto
>>> c = boto.connect_cloudwatch()
>>> metrics = c.list_metrics()
>>> metrics
[Metric:NetworkIn,
 Metric:NetworkOut,
 Metric:NetworkOut(InstanceType,m1.small),
 Metric:NetworkIn(InstanceId,i-e573e68c),
 Metric:CPUUtilization(InstanceId,i-e573e68c),
 Metric:DiskWriteBytes(InstanceType,m1.small),
 Metric:DiskWriteBytes(ImageId,ami-a1ffb63),
 Metric:NetworkOut(ImageId,ami-a1ffb63),
 Metric:DiskWriteOps(InstanceType,m1.small),
 Metric:DiskReadBytes(InstanceType,m1.small),
 Metric:DiskReadOps(ImageId,ami-a1ffb63),
 Metric:CPUUtilization(InstanceType,m1.small),
 Metric:NetworkIn(ImageId,ami-a1ffb63),
 Metric:DiskReadOps(InstanceType,m1.small),
 Metric:DiskReadBytes,
 Metric:CPUUtilization,
 Metric:DiskWriteBytes(InstanceId,i-e573e68c),
 Metric:DiskWriteOps(InstanceId,i-e573e68c),
 Metric:DiskWriteOps,
 Metric:DiskReadOps,
 Metric:CPUUtilization(ImageId,ami-a1ffb63),
 Metric:DiskReadOps(InstanceId,i-e573e68c),
 Metric:NetworkOut(InstanceId,i-e573e68c),
 Metric:DiskReadBytes(ImageId,ami-a1ffb63),
 Metric:DiskReadBytes(InstanceId,i-e573e68c),
 Metric:DiskWriteBytes,
 Metric:NetworkIn(InstanceType,m1.small),
 Metric:DiskWriteOps(ImageId,ami-a1ffb63)]

The list_metrics call will return a list of all of the available metrics that you can query against. Each entry in the list is a Metric object. As you can see from the list above, some of the metrics are generic metrics and some have Dimensions associated with them (e.g. InstanceType=m1.small). The Dimension can be used to refine your query. So, for example, I could query the metric Metric:CPUUtilization which would create the desired statistic by aggregating cpu utilization data across all sources of information available or I could refine that by querying the metric Metric:CPUUtilization(InstanceId,i-e573e68c) which would use only the data associated with the instance identified by the instance ID i-e573e68c.

Because for this example, I’m only monitoring a single instance, the set of metrics available to me are fairly limited. If I was monitoring many instances, using many different instance types and AMI’s and also several load balancers, the list of available metrics would grow considerably.

Once you have the list of available metrics, you can actually query the CloudWatch system for that metric. Let’s choose the CPU utilization metric for our instance.

>>> m = metrics[5]
>>> m
Metric:CPUUtilization(InstanceId,i-e573e68c)

The Metric object has a query method that lets us actually perform the query against the collected data in CloudWatch. To call that, we need a start time and end time to control the time span of data that we are interested in. For this example, let’s say we want the data for the previous hour:

>>> import datetime
>>> end = datetime.datetime.now()
>>> start = end - datetime.timedelta(hours=1)

We also need to supply the Statistic that we want reported and the Units to use for the results. The Statistic can be one of these values:

[‘Minimum’, ‘Maximum’, ‘Sum’, ‘Average’, ‘Samples’]

And Units must be one of the following:

[‘Seconds’, ‘Percent’, ‘Bytes’, ‘Bits’, ‘Count’, ‘Bytes/Second’, ‘Bits/Second’, ‘Count/Second’]

The query method also takes an optional parameter, period. This parameter controls the granularity (in seconds) of the data returned. The smallest period is 60 seconds and the value must be a multiple of 60 seconds. So, let’s ask for the average as a percent:

>>> datapoints = m.query(start, end, 'Average', 'Percent')
>>> len(datapoints)
60

Our period was 60 seconds and our duration was one hour so we should get 60 data points back and we can see that we did. Each element in the datapoints list is a DataPoint object which is a simple subclass of a Python dict object. Each Datapoint object contains all of the information available about that particular data point.

>>> d = datapoints[0]
>>> d
{u'Average': 0.0,
 u'Samples': 1.0,
 u'Timestamp': u'2009-05-21T19:55:00Z',
 u'Unit': u'Percent'}

My server obviously isn’t very busy right now!

class boto.ec2.cloudwatch.CloudWatchConnection(aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, host='monitoring.amazonaws.com', debug=0, https_connection_factory=None, path='/')
build_list_params(params, items, label)
get_metric_statistics(period, start_time, end_time, measure_name, namespace, statistics=None, dimensions=None, unit=None)

Get time-series data for one or more statistics of a given metric.

Parameter:measure_name (string) – CPUUtilization|NetworkIO-in|NetworkIO-out|DiskIO-ALL-read| DiskIO-ALL-write|DiskIO-ALL-read-bytes|DiskIO-ALL-write-bytes
Return type:list
Returns:A list of boto.ec2.image.Image
list_metrics(next_token=None)

Returns a list of the valid metrics for which there is recorded data available.

Parameter:next_token (string) – A maximum of 500 metrics will be returned at one time. If more results are available, the ResultSet returned will contain a non-Null next_token attribute. Passing that token as a parameter to list_metrics will retrieve the next page of metrics.

boto.ec2.cloudwatch.datapoint

class boto.ec2.cloudwatch.datapoint.Datapoint(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.cloudwatch.metric

class boto.ec2.cloudwatch.metric.Dimensions
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.cloudwatch.metric.Metric(connection=None)
endElement(name, value, connection)
query(start_time, end_time, statistic, unit, period=60)
startElement(name, attrs, connection)

boto.ec2.connection

Represents a connection to the EC2 service.

class boto.ec2.connection.EC2Connection(aws_access_key_id=None, aws_secret_access_key=None, is_secure=True, host=None, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, debug=0, https_connection_factory=None, region=None, path='/')
ResponseError
alias of EC2ResponseError
allocate_address()

Allocate a new Elastic IP address and associate it with your account.

Return type:L{boto.ec2.address.Address}
Returns:The newly allocated Address
associate_address(instance_id, public_ip)

Associate an Elastic IP address with a currently running instance.

Parameters:
  • instance_id (string) – The ID of the instance
  • public_ip (string) – The public IP address
Return type:

bool

Returns:

True if successful

attach_volume(volume_id, instance_id, device)

Attach an EBS volume to an EC2 instance.

Parameters:
  • volume_id (str) – The ID of the EBS volume to be attached.
  • instance_id (str) – The ID of the EC2 instance to which it will be attached.
  • device (str) – The device on the instance through which the volume will be exposted (e.g. /dev/sdh)
Return type:

bool

Returns:

True if successful

authorize_security_group(group_name, src_security_group_name=None, src_security_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None, cidr_ip=None)

Add a new rule to an existing security group. You need to pass in either src_security_group_name and src_security_group_owner_id OR ip_protocol, from_port, to_port, and cidr_ip. In other words, either you are authorizing another group or you are authorizing some ip-based rule.

Parameters:
  • group_name (string) – The name of the security group you are adding the rule to.
  • src_security_group_name (string) – The name of the security group you are granting access to.
  • src_security_group_owner_id (string) – The ID of the owner of the security group you are granting access to.
  • ip_protocol (string) – Either tcp | udp | icmp
  • from_port (int) – The beginning port number you are enabling
  • to_port – The ending port number you are enabling
  • to_port (string) – The CIDR block you are providing access to. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
Return type:

bool

Returns:

True if successful.

cancel_spot_instance_requests(request_ids)

Cancel the specified Spot Instance Requests.

Parameter:request_ids (list) – A list of strings of the Request IDs to terminate
Return type:list
Returns:A list of the instances terminated
confirm_product_instance(product_code, instance_id)
create_image(instance_id, name, description=None, no_reboot=False)

Will create an AMI from the instance in the running or stopped state.

Parameters:
  • instance_id (string) – the ID of the instance to image.
  • name (string) – The name of the new image
  • description (string) – An optional human-readable string describing the contents and purpose of the AMI.
  • no_reboot (bool) – An optional flag indicating that the bundling process should not attempt to shutdown the instance before bundling. If this flag is True, the responsibility of maintaining file system integrity is left to the owner of the instance.
Return type:

string

Returns:

The new image id

create_key_pair(key_name)

Create a new key pair for your account. This will create the key pair within the region you are currently connected to.

Parameter:key_name (string) – The name of the new keypair
Return type:boto.ec2.keypair.KeyPair
Returns:The newly created boto.ec2.keypair.KeyPair. The material attribute of the new KeyPair object will contain the the unencrypted PEM encoded RSA private key.
create_security_group(name, description)

Create a new security group for your account. This will create the security group within the region you are currently connected to.

Parameters:
  • name (string) – The name of the new security group
  • description (string) – The description of the new security group
Return type:

boto.ec2.securitygroup.SecurityGroup

Returns:

The newly created boto.ec2.keypair.KeyPair.

create_snapshot(volume_id, description=None)

Create a snapshot of an existing EBS Volume.

Parameters:
  • volume_id (str) – The ID of the volume to be snapshot’ed
  • description (str) – A description of the snapshot. Limited to 255 characters.
Return type:

bool

Returns:

True if successful

create_spot_datafeed_subscription(bucket, prefix)

Create a spot instance datafeed subscription for this account.

Parameters:
  • bucket (str or unicode) – The name of the bucket where spot instance data will be written. The account issuing this request must have FULL_CONTROL access to the bucket specified in the request.
  • prefix (str or unicode) – An optional prefix that will be pre-pended to all data files written to the bucket.
Return type:

:class:`boto.ec2.spotdatafeedsubscription.SpotDatafeedSubscription

Returns:

The datafeed subscription object or None

create_volume(size, zone, snapshot=None)

Create a new EBS Volume.

Parameters:
  • size (int) – The size of the new volume, in GiB
  • zone (string or L{boto.ec2.zone.Zone}) – The availability zone in which the Volume will be created.
  • snapshot (string or L{boto.ec2.snapshot.Snapshot}) – The snapshot from which the new Volume will be created.
delete_key_pair(key_name)

Delete a key pair from your account.

Parameter:key_name (string) – The name of the keypair to delete
delete_security_group(name)

Delete a security group from your account.

Parameter:key_name (string) – The name of the keypair to delete
delete_snapshot(snapshot_id)
delete_spot_datafeed_subscription()

Delete the current spot instance data feed subscription associated with this account

Return type:bool
Returns:True if successful
delete_volume(volume_id)

Delete an EBS volume.

Parameter:volume_id (str) – The ID of the volume to be delete.
Return type:bool
Returns:True if successful
deregister_image(image_id)

Unregister an AMI.

Parameter:image_id (string) – the ID of the Image to unregister
Return type:bool
Returns:True if successful
detach_volume(volume_id, instance_id=None, device=None, force=False)

Detach an EBS volume from an EC2 instance.

Parameters:
  • volume_id (str) – The ID of the EBS volume to be attached.
  • instance_id (str) – The ID of the EC2 instance from which it will be detached.
  • device (str) – The device on the instance through which the volume is exposted (e.g. /dev/sdh)
  • force (bool) – Forces detachment if the previous detachment attempt did not occur cleanly. This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures.
Return type:

bool

Returns:

True if successful

disassociate_address(public_ip)

Disassociate an Elastic IP address from a currently running instance.

Parameter:public_ip (string) – The public IP address
Return type:bool
Returns:True if successful
get_all_addresses(addresses=None)

Get all EIP’s associated with the current credentials.

Parameter:addresses (list) – Optional list of addresses. If this list is present, only the Addresses associated with these addresses will be returned.
Return type:list of L{boto.ec2.address.Address}
Returns:The requested Address objects
get_all_images(image_ids=None, owners=None, executable_by=None)

Retrieve all the EC2 images available on your account.

Parameters:
  • image_ids (list) – A list of strings with the image IDs wanted
  • owners (list) – A list of owner IDs
  • executable_by
Return type:

list

Returns:

A list of boto.ec2.image.Image

get_all_instances(instance_ids=None)

Retrieve all the instances associated with your account.

Parameter:instance_ids (list) – A list of strings of instance IDs
Return type:list
Returns:A list of boto.ec2.instance.Reservation
get_all_kernels(kernel_ids=None, owners=None)

Retrieve all the EC2 kernels available on your account. Simply filters the list returned by get_all_images because EC2 does not provide a way to filter server-side.

Parameters:
  • kernel_ids (list) – A list of strings with the image IDs wanted
  • owners (list) – A list of owner IDs
Return type:

list

Returns:

A list of boto.ec2.image.Image

get_all_key_pairs(keynames=None)

Get all key pairs associated with your account.

Parameter:keynames (list) – A list of the names of keypairs to retrieve. If not provided, all key pairs will be returned.
Return type:list
Returns:A list of boto.ec2.keypair.KeyPair
get_all_ramdisks(ramdisk_ids=None, owners=None)

Retrieve all the EC2 ramdisks available on your account. Simply filters the list returned by get_all_images because EC2 does not provide a way to filter server-side.

Parameters:
  • ramdisk_ids (list) – A list of strings with the image IDs wanted
  • owners (list) – A list of owner IDs
Return type:

list

Returns:

A list of boto.ec2.image.Image

get_all_regions()

Get all available regions for the EC2 service.

Return type:list
Returns:A list of boto.ec2.regioninfo.RegionInfo
get_all_reserved_instances(reserved_instances_id=None)

Describes Reserved Instance offerings that are available for purchase.

Parameter:reserved_instance_ids (list) – A list of the reserved instance ids that will be returned. If not provided, all reserved instances will be returned.
Return type:list
Returns:A list of boto.ec2.reservedinstance.ReservedInstance
get_all_reserved_instances_offerings(reserved_instances_id=None, instance_type=None, availability_zone=None, product_description=None)

Describes Reserved Instance offerings that are available for purchase.

Parameters:
  • reserved_instances_id (str) – Displays Reserved Instances with the specified offering IDs.
  • instance_type (str) – Displays Reserved Instances of the specified instance type.
  • availability_zone (str) – Displays Reserved Instances within the specified Availability Zone.
  • product_description (str) – Displays Reserved Instances with the specified product description.
Return type:

list

Returns:

A list of boto.ec2.reservedinstance.ReservedInstancesOffering

get_all_security_groups(groupnames=None)

Get all security groups associated with your account in a region.

Parameter:groupnames (list) – A list of the names of security groups to retrieve. If not provided, all security groups will be returned.
Return type:list
Returns:A list of boto.ec2.securitygroup.SecurityGroup
get_all_snapshots(snapshot_ids=None, owner=None, restorable_by=None)

Get all EBS Snapshots associated with the current credentials.

Parameters:
  • snapshot_ids (list) – Optional list of snapshot ids. If this list is present, only the Snapshots associated with these snapshot ids will be returned.
  • owner (str) – If present, only the snapshots owned by the specified user will be returned. Valid values are: self | amazon | AWS Account ID
  • restorable_by (str) – If present, only the snapshots that are restorable by the specified account id will be returned.
Return type:

list of L{boto.ec2.snapshot.Snapshot}

Returns:

The requested Snapshot objects

get_all_spot_instance_requests(request_ids=None)

Retrieve all the spot instances requests associated with your account.

@type request_ids: list @param request_ids: A list of strings of spot instance request IDs

@rtype: list @return: A list of

boto.ec2.spotinstancerequest.SpotInstanceRequest
get_all_volumes(volume_ids=None)

Get all Volumes associated with the current credentials.

Parameter:volume_ids (list) – Optional list of volume ids. If this list is present, only the volumes associated with these volume ids will be returned.
Return type:list of L{boto.ec2.volume.Volume}
Returns:The requested Volume objects
get_all_zones(zones=None)

Get all Availability Zones associated with the current region.

Parameter:zones (list) – Optional list of zones. If this list is present, only the Zones associated with these zone names will be returned.
Return type:list of L{boto.ec2.zone.Zone}
Returns:The requested Zone objects
get_console_output(instance_id)

Retrieves the console output for the specified instance. See http://docs.amazonwebservices.com/AWSEC2/2008-02-01/DeveloperGuide/ApiReference-Query-GetConsoleOutput.html

Parameter:instance_id (string) – The instance ID of a running instance on the cloud.
Return type:boto.ec2.instance.ConsoleOutput
Returns:The console output as a ConsoleOutput object
get_image(image_id)

Shortcut method to retrieve a specific image (AMI).

Parameter:image_id (string) – the ID of the Image to retrieve
Return type:boto.ec2.image.Image
Returns:The EC2 Image specified or None if the image is not found
get_image_attribute(image_id, attribute='launchPermission')

Gets an attribute from an image. See http://docs.amazonwebservices.com/AWSEC2/2008-02-01/DeveloperGuide/ApiReference-Query-DescribeImageAttribute.html

Parameters:
  • image_id (string) – The Amazon image id for which you want info about
  • attribute (string) – The attribute you need information about. Valid choices are: * launchPermission * productCodes * blockDeviceMapping
Return type:

boto.ec2.image.ImageAttribute

Returns:

An ImageAttribute object representing the value of the attribute requested

get_instance_attribute(instance_id, attribute)

Gets an attribute from an instance.

Parameters:
  • instance_id (string) – The Amazon id of the instance
  • attribute (string) – The attribute you need information about Valid choices are: instanceType|kernel|ramdisk|userData| disableApiTermination| instanceInitiatedShutdownBehavior| rootDeviceName|blockDeviceMapping
Return type:

boto.ec2.image.ImageAttribute

Returns:

An ImageAttribute object representing the value of the attribute requested

get_key_pair(keyname)

Convenience method to retrieve a specific keypair (KeyPair).

Parameter:image_id (string) – the ID of the Image to retrieve
Return type:boto.ec2.keypair.KeyPair
Returns:The KeyPair specified or None if it is not found
get_params()
Returns a dictionary containing the value of of all of the keyword arguments passed when constructing this connection.
get_snapshot_attribute(snapshot_id, attribute='createVolumePermission')

Get information about an attribute of a snapshot. Only one attribute can be specified per call.

Parameters:
  • snapshot_id (str) – The ID of the snapshot.
  • attribute (str) – The requested attribute. Valid values are: createVolumePermission
Return type:

list of L{boto.ec2.snapshotattribute.SnapshotAttribute}

Returns:

The requested Snapshot attribute

get_spot_datafeed_subscription()

Return the current spot instance data feed subscription associated with this account, if any.

Return type::class:`boto.ec2.spotdatafeedsubscription.SpotDatafeedSubscription
Returns:The datafeed subscription object or None
get_spot_price_history(start_time=None, end_time=None, instance_type=None, product_description=None)

Retrieve the recent history of spot instances pricing.

@type start_time: str @param start_time: An indication of how far back to provide price

changes for. An ISO8601 DateTime string.

@type end_time: str @param end_time: An indication of how far forward to provide price

changes for. An ISO8601 DateTime string.

@type instance_type: str @param instance_type: Filter responses to a particular instance type.

@type product_description: str @param product_descripton: Filter responses to a particular platform.

Valid values are currently: Linux

@rtype: list @return: A list tuples containing price and timestamp.

modify_image_attribute(image_id, attribute='launchPermission', operation='add', user_ids=None, groups=None, product_codes=None)

Changes an attribute of an image. See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ModifyImageAttribute.html

Parameters:
  • image_id (string) – The image id you wish to change
  • attribute (string) – The attribute you wish to change
  • operation (string) – Either add or remove (this is required for changing launchPermissions)
  • user_ids (list) – The Amazon IDs of users to add/remove attributes
  • groups (list) – The groups to add/remove attributes
  • product_codes (list) – Amazon DevPay product code. Currently only one product code can be associated with an AMI. Once set, the product code cannot be changed or reset.
modify_instance_attribute(instance_id, attribute, value)

Changes an attribute of an instance

Parameters:
  • instance_id (string) – The instance id you wish to change
  • attribute (string) – The attribute you wish to change. AttributeName - Expected value (default) instanceType - A valid instance type (m1.small) kernel - Kernel ID (None) ramdisk - Ramdisk ID (None) userData - Base64 encoded String (None) disableApiTermination - Boolean (true) instanceInitiatedShutdownBehavior - stop|terminate rootDeviceName - device name (None)
  • value (string) – The new value for the attribute
Return type:

bool

Returns:

Whether the operation succeeded or not

modify_snapshot_attribute(snapshot_id, attribute='createVolumePermission', operation='add', user_ids=None, groups=None)

Changes an attribute of an image.

Parameters:
  • snapshot_id (string) – The snapshot id you wish to change
  • attribute (string) – The attribute you wish to change. Valid values are: createVolumePermission
  • operation (string) – Either add or remove (this is required for changing snapshot ermissions)
  • user_ids (list) – The Amazon IDs of users to add/remove attributes
  • groups (list) – The groups to add/remove attributes. The only valid value at this time is ‘all’.
monitor_instance(instance_id)

Enable CloudWatch monitoring for the supplied instance.

Parameter:instance_id (string) – The instance id
Return type:list
Returns:A list of boto.ec2.instanceinfo.InstanceInfo
purchase_reserved_instance_offering(reserved_instances_offering_id, instance_count=1)

Purchase a Reserved Instance for use with your account. ** CAUTION ** This request can result in large amounts of money being charged to your AWS account. Use with caution!

Parameters:
  • reserved_instances_offering_id (string) – The offering ID of the Reserved Instance to purchase
  • instance_count (int) – The number of Reserved Instances to purchase. Default value is 1.
Return type:

boto.ec2.reservedinstance.ReservedInstance

Returns:

The newly created Reserved Instance

reboot_instances(instance_ids=None)

Reboot the specified instances.

Parameter:instance_ids (list) – The instances to terminate and reboot
register_image(name=None, description=None, image_location=None, architecture=None, kernel_id=None, ramdisk_id=None, root_device_name=None, block_device_map=None)

Register an image.

Parameters:
  • name (string) – The name of the AMI. Valid only for EBS-based images.
  • description (string) – The description of the AMI.
  • image_location (string) – Full path to your AMI manifest in Amazon S3 storage. Only used for S3-based AMI’s.
  • architecture (string) – The architecture of the AMI. Valid choices are: i386 | x86_64
  • kernel_id (string) – The ID of the kernel with which to launch the instances
  • root_device_name (string) – The root device name (e.g. /dev/sdh)
  • block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.
Return type:

string

Returns:

The new image id

release_address(public_ip)

Free up an Elastic IP address

Parameter:public_ip (string) – The public IP address
Return type:bool
Returns:True if successful
request_spot_instances(price, image_id, count=1, type=None, valid_from=None, valid_until=None, launch_group=None, availability_zone_group=None, key_name=None, security_groups=None, user_data=None, addressing_type=None, instance_type='m1.small', placement=None, kernel_id=None, ramdisk_id=None, monitoring_enabled=False, subnet_id=None, block_device_map=None)

Request instances on the spot market at a particular price.

Parameters:
  • price (str) – The maximum price of your bid
  • image_id (string) – The ID of the image to run
  • count (int) – The of instances to requested
  • type (str) – Type of request. Can be ‘one-time’ or ‘persistent’. Default is one-time.
  • valid_from (str) – Start date of the request. An ISO8601 time string.
  • valid_until (str) – End date of the request. An ISO8601 time string.
  • launch_group (str) – If supplied, all requests will be fulfilled as a group.
  • availability_zone_group (str) – If supplied, all requests will be fulfilled within a single availability zone.
  • key_name (string) – The name of the key pair with which to launch instances
  • security_groups (list of strings) – The names of the security groups with which to associate instances
  • user_data (string) – The user data passed to the launched instances
  • instance_type (string) – The type of instance to run (m1.small, m1.large, m1.xlarge)
  • placement (string) – The availability zone in which to launch the instances
  • kernel_id (string) – The ID of the kernel with which to launch the instances
  • ramdisk_id (string) – The ID of the RAM disk with which to launch the instances
  • monitoring_enabled (bool) – Enable CloudWatch monitoring on the instance.
  • subnet_id (string) – The subnet ID within which to launch the instances for VPC.
  • block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.
Return type:

Reservation

Returns:

The boto.ec2.instance.Reservation associated with the request for machines

reset_image_attribute(image_id, attribute='launchPermission')

Resets an attribute of an AMI to its default value. See http://docs.amazonwebservices.com/AWSEC2/2008-02-01/DeveloperGuide/ApiReference-Query-ResetImageAttribute.html

Parameters:
  • image_id (string) – ID of the AMI for which an attribute will be described
  • attribute (string) – The attribute to reset
Return type:

bool

Returns:

Whether the operation succeeded or not

reset_instance_attribute(instance_id, attribute)

Resets an attribute of an instance to its default value.

Parameters:
  • instance_id (string) – ID of the instance
  • attribute (string) – The attribute to reset. Valid values are: kernel|ramdisk
Return type:

bool

Returns:

Whether the operation succeeded or not

reset_snapshot_attribute(snapshot_id, attribute='createVolumePermission')

Resets an attribute of a snapshot to its default value.

Parameters:
  • snapshot_id (string) – ID of the snapshot
  • attribute (string) – The attribute to reset
Return type:

bool

Returns:

Whether the operation succeeded or not

revoke_security_group(group_name, src_security_group_name=None, src_security_group_owner_id=None, ip_protocol=None, from_port=None, to_port=None, cidr_ip=None)

Remove an existing rule from an existing security group. You need to pass in either src_security_group_name and src_security_group_owner_id OR ip_protocol, from_port, to_port, and cidr_ip. In other words, either you are revoking another group or you are revoking some ip-based rule.

Parameters:
  • group_name (string) – The name of the security group you are removing the rule from.
  • src_security_group_name (string) – The name of the security group you are revoking access to.
  • src_security_group_owner_id (string) – The ID of the owner of the security group you are revoking access to.
  • ip_protocol (string) – Either tcp | udp | icmp
  • from_port (int) – The beginning port number you are disabling
  • to_port – The ending port number you are disabling
  • to_port (string) – The CIDR block you are revoking access to. See http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
Return type:

bool

Returns:

True if successful.

run_instances(image_id, min_count=1, max_count=1, key_name=None, security_groups=None, user_data=None, addressing_type=None, instance_type='m1.small', placement=None, kernel_id=None, ramdisk_id=None, monitoring_enabled=False, subnet_id=None, block_device_map=None)

Runs an image on EC2.

Parameters:
  • image_id (string) – The ID of the image to run
  • min_count (int) – The minimum number of instances to launch
  • max_count (int) – The maximum number of instances to launch
  • key_name (string) – The name of the key pair with which to launch instances
  • security_groups (list of strings) – The names of the security groups with which to associate instances
  • user_data (string) – The user data passed to the launched instances
  • instance_type (string) – The type of instance to run (m1.small, m1.large, m1.xlarge)
  • placement (string) – The availability zone in which to launch the instances
  • kernel_id (string) – The ID of the kernel with which to launch the instances
  • ramdisk_id (string) – The ID of the RAM disk with which to launch the instances
  • monitoring_enabled (bool) – Enable CloudWatch monitoring on the instance.
  • subnet_id (string) – The subnet ID within which to launch the instances for VPC.
  • block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.
Return type:

Reservation

Returns:

The boto.ec2.instance.Reservation associated with the request for machines

start_instances(instance_ids=None)

Start the instances specified

Parameter:instance_ids (list) – A list of strings of the Instance IDs to start
Return type:list
Returns:A list of the instances started
stop_instances(instance_ids=None)

Stop the instances specified

Parameter:instance_ids (list) – A list of strings of the Instance IDs to stop
Return type:list
Returns:A list of the instances stopped
terminate_instances(instance_ids=None)

Terminate the instances specified

Parameter:instance_ids (list) – A list of strings of the Instance IDs to terminate
Return type:list
Returns:A list of the instances terminated
unmonitor_instance(instance_id)

Disable CloudWatch monitoring for the supplied instance.

Parameter:instance_id (string) – The instance id
Return type:list
Returns:A list of boto.ec2.instanceinfo.InstanceInfo

boto.ec2.ec2object

Represents an EC2 Object

class boto.ec2.ec2object.EC2Object(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.elb

This module provides an interface to the Elastic Compute Cloud (EC2) load balancing service from AWS.

class boto.ec2.elb.ELBConnection(aws_access_key_id=None, aws_secret_access_key=None, is_secure=False, port=None, proxy=None, proxy_port=None, proxy_user=None, proxy_pass=None, host='elasticloadbalancing.amazonaws.com', debug=0, https_connection_factory=None, path='/')
build_list_params(params, items, label)
configure_health_check(name, health_check)

Define a health check for the EndPoints.

Parameters:
  • name (string) – The mnemonic name associated with the new access point
  • health_check (boto.ec2.elb.healthcheck.HealthCheck) – A HealthCheck object populated with the desired values.
Return type:

boto.ec2.elb.healthcheck.HealthCheck

Returns:

The updated boto.ec2.elb.healthcheck.HealthCheck

create_load_balancer(name, zones, listeners)

Create a new load balancer for your account.

Parameters:
  • name (string) – The mnemonic name associated with the new load balancer
  • zones (List of strings) – The names of the availability zone(s) to add.
  • listeners (List of tuples) – Each tuple contains three values. (LoadBalancerPortNumber, InstancePortNumber, Protocol) where LoadBalancerPortNumber and InstancePortNumber are integer values between 1 and 65535 and Protocol is a string containing either ‘TCP’ or ‘HTTP’.
Return type:

boto.ec2.elb.loadbalancer.LoadBalancer

Returns:

The newly created boto.ec2.elb.loadbalancer.LoadBalancer

delete_load_balancer(name)

Delete a Load Balancer from your account.

Parameter:name (string) – The name of the Load Balancer to delete
deregister_instances(load_balancer_name, instances)

Remove Instances from an existing Load Balancer.

Parameters:
  • load_balancer_name (string) – The name of the Load Balancer
  • instances (List of strings) – The instance ID’s of the EC2 instances to remove.
Return type:

List of strings

Returns:

An updated list of instances for this Load Balancer.

describe_instance_health(load_balancer_name, instances=None)

Get current state of all Instances registered to an Load Balancer.

Parameters:
  • load_balancer_name (string) – The name of the Load Balancer
  • instances (List of strings) – The instance ID’s of the EC2 instances to return status for. If not provided, the state of all instances will be returned.
Return type:

List of boto.ec2.elb.instancestate.InstanceState

Returns:

list of state info for instances in this Load Balancer.

disable_availability_zones(load_balancer_name, zones_to_remove)

Remove availability zones from an existing Load Balancer. All zones must be in the same region as the Load Balancer. Removing zones that are not registered with the Load Balancer has no effect. You cannot remove all zones from an Load Balancer.

Parameters:
  • load_balancer_name (string) – The name of the Load Balancer
  • zones (List of strings) – The name of the zone(s) to remove.
Return type:

List of strings

Returns:

An updated list of zones for this Load Balancer.

enable_availability_zones(load_balancer_name, zones_to_add)

Add availability zones to an existing Load Balancer All zones must be in the same region as the Load Balancer Adding zones that are already registered with the Load Balancer has no effect.

Parameters:
  • load_balancer_name (string) – The name of the Load Balancer
  • zones (List of strings) – The name of the zone(s) to add.
Return type:

List of strings

Returns:

An updated list of zones for this Load Balancer.

get_all_load_balancers(load_balancer_name=None)

Retrieve all load balancers associated with your account.

Parameter:load_balancer_names (str) – An optional filter string to get only one ELB
Return type:list
Returns:A list of boto.ec2.elb.loadbalancer.LoadBalancer
register_instances(load_balancer_name, instances)

Add new Instances to an existing Load Balancer.

Parameters:
  • load_balancer_name (string) – The name of the Load Balancer
  • instances (List of strings) – The instance ID’s of the EC2 instances to add.
Return type:

List of strings

Returns:

An updated list of instances for this Load Balancer.

boto.ec2.elb.healthcheck

class boto.ec2.elb.healthcheck.HealthCheck(access_point=None, interval=30, target=None, healthy_threshold=3, timeout=5, unhealthy_threshold=5)

Represents an EC2 Access Point Health Check

endElement(name, value, connection)
startElement(name, attrs, connection)
update()

boto.ec2.elb.instancestate

class boto.ec2.elb.instancestate.InstanceState(load_balancer=None, description=None, state=None, instance_id=None, reason_code=None)

Represents the state of an EC2 Load Balancer Instance

endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.elb.listelement

class boto.ec2.elb.listelement.ListElement
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.elb.listener

class boto.ec2.elb.listener.Listener(load_balancer=None, load_balancer_port=0, instance_port=0, protocol='')

Represents an EC2 Load Balancer Listener tuple

endElement(name, value, connection)
get_tuple()
startElement(name, attrs, connection)

boto.ec2.elb.loadbalancer

class boto.ec2.elb.loadbalancer.LoadBalancer(connection=None, name=None, endpoints=None)

Represents an EC2 Load Balancer

configure_health_check(health_check)
delete()
Delete this load balancer
deregister_instances(instances)

Remove instances from this Load Balancer. Removing instances that are not registered with the Load Balancer has no effect.

Parameter:zones (string or List of instance id’s) – The name of the endpoint(s) to add.
disable_zones(zones)

Disable availability zones from this Access Point.

Parameter:zones (string or List of strings) – The name of the zone(s) to add.
enable_zones(zones)

Enable availability zones to this Access Point. All zones must be in the same region as the Access Point.

Parameter:zones (string or List of strings) – The name of the zone(s) to add.
endElement(name, value, connection)
get_instance_health(instances=None)
register_instances(instances)

Add instances to this Load Balancer All instances must be in the same region as the Load Balancer. Adding endpoints that are already registered with the Load Balancer has no effect.

Parameter:zones (string or List of instance id’s) – The name of the endpoint(s) to add.
startElement(name, attrs, connection)

boto.ec2.image

class boto.ec2.image.Image(connection=None)

Represents an EC2 Image

deregister()
endElement(name, value, connection)
get_kernel()
get_launch_permissions()
get_ramdisk()
remove_launch_permissions(user_ids=None, group_names=None)
reset_launch_attributes()
run(min_count=1, max_count=1, key_name=None, security_groups=None, user_data=None, addressing_type=None, instance_type='m1.small', placement=None, kernel_id=None, ramdisk_id=None, monitoring_enabled=False, subnet_id=None, block_device_map=None)

Runs this instance.

Parameters:
  • min_count (int) – The minimum number of instances to start
  • max_count (int) – The maximum number of instances to start
  • key_name (string) – The keypair to run this instance with.
  • security_groups
  • user_data
  • daddressing_type
  • instance_type (string) – The type of instance to run (m1.small, m1.large, m1.xlarge)
  • placement
  • kernel_id (string) – The ID of the kernel with which to launch the instances
  • ramdisk_id (string) – The ID of the RAM disk with which to launch the instances
  • monitoring_enabled (bool) – Enable CloudWatch monitoring on the instance.
  • subnet_id (string) – The subnet ID within which to launch the instances for VPC.
  • block_device_map (boto.ec2.blockdevicemapping.BlockDeviceMapping) – A BlockDeviceMapping data structure describing the EBS volumes associated with the Image.
Return type:

Reservation

Returns:

The boto.ec2.instance.Reservation associated with the request for machines

set_launch_permissions(user_ids=None, group_names=None)
startElement(name, attrs, connection)
class boto.ec2.image.ImageAttribute(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.image.ProductCodes
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.instance

Represents an EC2 Instance

class boto.ec2.instance.ConsoleOutput(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.instance.Group(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.instance.Instance(connection=None)
confirm_product(product_code)
endElement(name, value, connection)
get_console_output()
monitor()
reboot()
start()
startElement(name, attrs, connection)
stop()
terminate()
unmonitor()
update()
use_ip(ip_address)
class boto.ec2.instance.InstanceAttribute(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.instance.Reservation(connection=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
stop_all()

boto.ec2.instanceinfo

class boto.ec2.instanceinfo.InstanceInfo(connection=None, id=None, state=None)

Represents an EC2 Instance status response from CloudWatch

endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.keypair

Represents an EC2 Keypair

class boto.ec2.keypair.KeyPair(connection=None)
copy_to_region(region)

Create a new key pair of the same new in another region. Note that the new key pair will use a different ssh cert than the this key pair. After doing the copy, you will need to save the material associated with the new key pair (use the save method) to a local file.

Parameter:region (boto.ec2.regioninfo.RegionInfo) – The region to which this security group will be copied.
Return type:boto.ec2.keypair.KeyPair
Returns:The new key pair
delete()

Delete the KeyPair.

Return type:bool
Returns:True if successful, otherwise False.
endElement(name, value, connection)
save(directory_path)

Save the material (the unencrypted PEM encoded RSA private key) of a newly created KeyPair to a local file.

Parameter:directory_path (string) – The fully qualified path to the directory in which the keypair will be saved. The keypair file will be named using the name of the keypair as the base name and .pem for the file extension. If a file of that name already exists in the directory, an exception will be raised and the old file will not be overwritten.
Return type:bool
Returns:True if successful.

boto.ec2.regioninfo

class boto.ec2.regioninfo.RegionInfo(connection=None, name=None, endpoint=None)

Represents an EC2 Region

connect(**kw_params)

Connect to this Region’s endpoint. Returns an EC2Connection object pointing to the endpoint associated with this region. You may pass any of the arguments accepted by the EC2Connection object’s constructor as keyword arguments and they will be passed along to the EC2Connection object.

Return type:boto.ec2.connection.EC2Connection
Returns:The connection to this regions endpoint
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.reservedinstance

class boto.ec2.reservedinstance.ReservedInstance(connection=None, id=None, instance_type=None, availability_zone=None, duration=None, fixed_price=None, usage_price=None, description=None, instance_count=None, state=None)
endElement(name, value, connection)
class boto.ec2.reservedinstance.ReservedInstancesOffering(connection=None, id=None, instance_type=None, availability_zone=None, duration=None, fixed_price=None, usage_price=None, description=None)
describe()
endElement(name, value, connection)
purchase(instance_count=1)
startElement(name, attrs, connection)

boto.ec2.securitygroup

Represents an EC2 Security Group

class boto.ec2.securitygroup.GroupOrCIDR(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.securitygroup.IPPermissions(parent=None)
add_grant(name=None, owner_id=None, cidr_ip=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.securitygroup.SecurityGroup(connection=None, owner_id=None, name=None, description=None)
add_rule(ip_protocol, from_port, to_port, src_group_name, src_group_owner_id, cidr_ip)
authorize(ip_protocol=None, from_port=None, to_port=None, cidr_ip=None, src_group=None)

Add a new rule to this security group. You need to pass in either src_group_name OR ip_protocol, from_port, to_port, and cidr_ip. In other words, either you are authorizing another group or you are authorizing some ip-based rule.

Parameters:
Return type:

bool

Returns:

True if successful.

copy_to_region(region, name=None)

Create a copy of this security group in another region. Note that the new security group will be a separate entity and will not stay in sync automatically after the copy operation.

Parameters:
  • region (boto.ec2.regioninfo.RegionInfo) – The region to which this security group will be copied.
  • name (string) – The name of the copy. If not supplied, the copy will have the same name as this security group.
Return type:

boto.ec2.securitygroup.SecurityGroup

Returns:

The new security group.

delete()
endElement(name, value, connection)
instances()
remove_rule(ip_protocol, from_port, to_port, src_group_name, src_group_owner_id, cidr_ip)
revoke(ip_protocol=None, from_port=None, to_port=None, cidr_ip=None, src_group=None)
startElement(name, attrs, connection)

boto.ec2.snapshot

Represents an EC2 Elastic IP Snapshot

class boto.ec2.snapshot.Snapshot(connection=None)
delete()
endElement(name, value, connection)
get_permissions()
reset_permissions()
share(user_ids=None, groups=None)
unshare(user_ids=None, groups=None)
update()
class boto.ec2.snapshot.SnapshotAttribute(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)

boto.ec2.volume

Represents an EC2 Elastic Block Storage Volume

class boto.ec2.volume.AttachmentSet
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.ec2.volume.Volume(connection=None)
attach(instance_id, device)

Attach this EBS volume to an EC2 instance.

Parameters:
  • instance_id (str) – The ID of the EC2 instance to which it will be attached.
  • device (str) – The device on the instance through which the volume will be exposted (e.g. /dev/sdh)
Return type:

bool

Returns:

True if successful

attachment_state()
Get the attachment state.
create_snapshot(description=None)

Create a snapshot of this EBS Volume.

Parameter:description (str) – A description of the snapshot. Limited to 256 characters.
Return type:bool
Returns:True if successful
delete()

Delete this EBS volume.

Return type:bool
Returns:True if successful
detach(force=False)

Detach this EBS volume from an EC2 instance.

Parameter:force (bool) – Forces detachment if the previous detachment attempt did not occur cleanly. This option can lead to data loss or a corrupted file system. Use this option only as a last resort to detach a volume from a failed instance. The instance will not have an opportunity to flush file system caches nor file system meta data. If you use this option, you must perform file system check and repair procedures.
Return type:bool
Returns:True if successful
endElement(name, value, connection)
snapshots(owner=None, restorable_by=None)

Get all snapshots related to this volume. Note that this requires that all available snapshots for the account be retrieved from EC2 first and then the list is filtered client-side to contain only those for this volume.

Parameters:
  • owner (str) – If present, only the snapshots owned by the specified user will be returned. Valid values are: self | amazon | AWS Account ID
  • restorable_by (str) – If present, only the snapshots that are restorable by the specified account id will be returned.
Return type:

list of L{boto.ec2.snapshot.Snapshot}

Returns:

The requested Snapshot objects

startElement(name, attrs, connection)
update()
volume_state()
Returns the state of the volume. Same value as the status attribute.

boto.ec2.zone

Represents an EC2 Availability Zone

class boto.ec2.zone.Zone(connection=None)
endElement(name, value, connection)