This module provides an interface to the Elastic Compute Cloud (EC2) service from AWS.
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 |
Represents an EC2 Elastic IP Address
This module provides an interface to the Elastic Compute Cloud (EC2) Auto Scaling service.
Creates a new Launch Configuration.
| Parameter: | launch_config (boto.ec2.autoscale.launchconfig.LaunchConfiguration) – LaunchConfiguraiton object. |
|---|
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.
An auto scaling trigger.
This module provides an interface to the Elastic Compute Cloud (EC2) CloudWatch service from AWS.
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!
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 |
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. |
|---|
Represents a connection to the EC2 service.
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 an Elastic IP address with a currently running instance.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful |
Attach an EBS volume to an EC2 instance.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful |
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: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful. |
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 |
Will create an AMI from the instance in the running or stopped state.
| Parameters: |
|
|---|---|
| Return type: | string |
| Returns: | The new image id |
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 a new security group for your account. This will create the security group within the region you are currently connected to.
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | The newly created boto.ec2.keypair.KeyPair. |
Create a snapshot of an existing EBS Volume.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful |
Create a spot instance datafeed subscription for this account.
| Parameters: |
|
|---|---|
| Return type: | :class:`boto.ec2.spotdatafeedsubscription.SpotDatafeedSubscription |
| Returns: | The datafeed subscription object or None |
Create a new EBS Volume.
| Parameters: |
|
|---|
Delete a key pair from your account.
| Parameter: | key_name (string) – The name of the keypair to delete |
|---|
Delete a security group from your account.
| Parameter: | key_name (string) – The name of the keypair to delete |
|---|
Delete the current spot instance data feed subscription associated with this account
| Return type: | bool |
|---|---|
| Returns: | True if successful |
Delete an EBS volume.
| Parameter: | volume_id (str) – The ID of the volume to be delete. |
|---|---|
| Return type: | bool |
| Returns: | True if successful |
Unregister an AMI.
| Parameter: | image_id (string) – the ID of the Image to unregister |
|---|---|
| Return type: | bool |
| Returns: | True if successful |
Detach an EBS volume from an EC2 instance.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful |
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 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 |
Retrieve all the EC2 images available on your account.
| Parameters: |
|
|---|---|
| Return type: | list |
| Returns: | A list of boto.ec2.image.Image |
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 |
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: |
|
|---|---|
| Return type: | list |
| Returns: | A list of boto.ec2.image.Image |
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 |
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: |
|
|---|---|
| Return type: | list |
| Returns: | A list of boto.ec2.image.Image |
Get all available regions for the EC2 service.
| Return type: | list |
|---|---|
| Returns: | A list of boto.ec2.regioninfo.RegionInfo |
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 |
Describes Reserved Instance offerings that are available for purchase.
| Parameters: |
|
|---|---|
| Return type: | list |
| Returns: | A list of boto.ec2.reservedinstance.ReservedInstancesOffering |
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 EBS Snapshots associated with the current credentials.
| Parameters: |
|
|---|---|
| Return type: | list of L{boto.ec2.snapshot.Snapshot} |
| Returns: | The requested Snapshot objects |
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 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 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 |
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 |
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 |
Gets an attribute from an image. See http://docs.amazonwebservices.com/AWSEC2/2008-02-01/DeveloperGuide/ApiReference-Query-DescribeImageAttribute.html
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | An ImageAttribute object representing the value of the attribute requested |
Gets an attribute from an instance.
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | An ImageAttribute object representing the value of the attribute requested |
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 information about an attribute of a snapshot. Only one attribute can be specified per call.
| Parameters: |
|
|---|---|
| Return type: | list of L{boto.ec2.snapshotattribute.SnapshotAttribute} |
| Returns: | The requested Snapshot attribute |
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 |
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.
Changes an attribute of an image. See http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-ModifyImageAttribute.html
| Parameters: |
|
|---|
Changes an attribute of an instance
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | Whether the operation succeeded or not |
Changes an attribute of an image.
| Parameters: |
|
|---|
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 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: |
|
|---|---|
| Return type: | |
| Returns: | The newly created Reserved Instance |
Reboot the specified instances.
| Parameter: | instance_ids (list) – The instances to terminate and reboot |
|---|
Register an image.
| Parameters: |
|
|---|---|
| Return type: | string |
| Returns: | The new image id |
Free up an Elastic IP address
| Parameter: | public_ip (string) – The public IP address |
|---|---|
| Return type: | bool |
| Returns: | True if successful |
Request instances on the spot market at a particular price.
| Parameters: |
|
|---|---|
| Return type: | Reservation |
| Returns: | The boto.ec2.instance.Reservation associated with the request for machines |
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: |
|
|---|---|
| Return type: | bool |
| Returns: | Whether the operation succeeded or not |
Resets an attribute of an instance to its default value.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | Whether the operation succeeded or not |
Resets an attribute of a snapshot to its default value.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | Whether the operation succeeded or not |
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: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful. |
Runs an image on EC2.
| Parameters: |
|
|---|---|
| Return type: | Reservation |
| Returns: | The boto.ec2.instance.Reservation associated with the request for machines |
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 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 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 |
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 |
Represents an EC2 Object
This module provides an interface to the Elastic Compute Cloud (EC2) load balancing service from AWS.
Define a health check for the EndPoints.
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | The updated boto.ec2.elb.healthcheck.HealthCheck |
Create a new load balancer for your account.
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | The newly created boto.ec2.elb.loadbalancer.LoadBalancer |
Delete a Load Balancer from your account.
| Parameter: | name (string) – The name of the Load Balancer to delete |
|---|
Remove Instances from an existing Load Balancer.
| Parameters: |
|
|---|---|
| Return type: | List of strings |
| Returns: | An updated list of instances for this Load Balancer. |
Get current state of all Instances registered to an Load Balancer.
| Parameters: |
|
|---|---|
| Return type: | |
| Returns: | list of state info for instances in this Load Balancer. |
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: |
|
|---|---|
| Return type: | List of strings |
| Returns: | An updated list of zones for this Load Balancer. |
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: |
|
|---|---|
| Return type: | List of strings |
| Returns: | An updated list of zones for this Load Balancer. |
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 |
Add new Instances to an existing Load Balancer.
| Parameters: |
|
|---|---|
| Return type: | List of strings |
| Returns: | An updated list of instances for this Load Balancer. |
Represents an EC2 Load Balancer
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 availability zones from this Access Point.
| Parameter: | zones (string or List of strings) – The name of the zone(s) to add. |
|---|
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. |
|---|
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. |
|---|
Represents an EC2 Image
Runs this instance.
| Parameters: |
|
|---|---|
| Return type: | Reservation |
| Returns: | The boto.ec2.instance.Reservation associated with the request for machines |
Represents an EC2 Instance
Represents an EC2 Keypair
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 the KeyPair.
| Return type: | bool |
|---|---|
| Returns: | True if successful, otherwise False. |
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. |
Represents an EC2 Region
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 |
Represents an EC2 Security Group
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. |
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: |
|
|---|---|
| Return type: | |
| Returns: | The new security group. |
Represents an EC2 Elastic IP Snapshot
Represents an EC2 Elastic Block Storage Volume
Attach this EBS volume to an EC2 instance.
| Parameters: |
|
|---|---|
| Return type: | bool |
| Returns: | True if successful |
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 this EBS volume.
| Return type: | bool |
|---|---|
| Returns: | True if successful |
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 |
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: |
|
|---|---|
| Return type: | list of L{boto.ec2.snapshot.Snapshot} |
| Returns: | The requested Snapshot objects |