boto

boto

class boto.NullHandler(level=0)

Initializes the instance - basically setting the formatter to None and the filter list to empty.

emit(record)
boto.check_extensions(module_name, module_path)

This function checks for extensions to boto modules. It should be called in the __init__.py file of all boto modules. See: http://code.google.com/p/boto/wiki/ExtendModules

for details.

boto.connect_autoscale(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ec2.autoscale.AutoScaleConnection

Returns:

A connection to Amazon’s Auto Scaling Service

boto.connect_cloudfront(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.fps.connection.FPSConnection

Returns:

A connection to FPS

boto.connect_cloudwatch(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ec2.cloudwatch.CloudWatchConnection

Returns:

A connection to Amazon’s EC2 Monitoring service

boto.connect_ec2(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ec2.connection.EC2Connection

Returns:

A connection to Amazon’s EC2

boto.connect_elb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ec2.elb.ELBConnection

Returns:

A connection to Amazon’s Load Balancing Service

boto.connect_emr(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.emr.EmrConnection

Returns:

A connection to Elastic mapreduce

boto.connect_euca(host, aws_access_key_id=None, aws_secret_access_key=None, port=8773, path='/services/Eucalyptus', is_secure=False, **kwargs)

Connect to a Eucalyptus service.

Parameters:
  • host (string) – the host name or ip address of the Eucalyptus server
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ec2.connection.EC2Connection

Returns:

A connection to Eucalyptus server

boto.connect_fps(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.fps.connection.FPSConnection

Returns:

A connection to FPS

boto.connect_gs(gs_access_key_id=None, gs_secret_access_key=None, **kwargs)

@type gs_access_key_id: string @param gs_access_key_id: Your Google Storage Access Key ID

@type gs_secret_access_key: string @param gs_secret_access_key: Your Google Storage Secret Access Key

@rtype: L{GSConnection<boto.gs.connection.GSConnection>} @return: A connection to Google’s Storage service

boto.connect_ia(ia_access_key_id=None, ia_secret_access_key=None, is_secure=False, **kwargs)

Connect to the Internet Archive via their S3-like API.

Parameters:
  • ia_access_key_id (string) – Your IA Access Key ID. This will also look in your boto config file for an entry in the Credentials section called “ia_access_key_id”
  • ia_secret_access_key (string) – Your IA Secret Access Key. This will also look in your boto config file for an entry in the Credentials section called “ia_secret_access_key”
Return type:

boto.s3.connection.S3Connection

Returns:

A connection to the Internet Archive

boto.connect_iam(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.iam.IAMConnection

Returns:

A connection to Amazon’s IAM

boto.connect_mturk(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.mturk.connection.MTurkConnection

Returns:

A connection to MTurk

boto.connect_rds(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.rds.RDSConnection

Returns:

A connection to RDS

boto.connect_route53(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.dns.Route53Connection

Returns:

A connection to Amazon’s Route53 DNS Service

boto.connect_s3(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.s3.connection.S3Connection

Returns:

A connection to Amazon’s S3

boto.connect_sdb(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.sdb.connection.SDBConnection

Returns:

A connection to Amazon’s SDB

boto.connect_ses(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.ses.SESConnection

Returns:

A connection to Amazon’s SES

boto.connect_sns(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.sns.SNSConnection

Returns:

A connection to Amazon’s SNS

boto.connect_sqs(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.sqs.connection.SQSConnection

Returns:

A connection to Amazon’s SQS

boto.connect_vpc(aws_access_key_id=None, aws_secret_access_key=None, **kwargs)
Parameters:
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.vpc.VPCConnection

Returns:

A connection to VPC

boto.connect_walrus(host, aws_access_key_id=None, aws_secret_access_key=None, port=8773, path='/services/Walrus', is_secure=False, **kwargs)

Connect to a Walrus service.

Parameters:
  • host (string) – the host name or ip address of the Walrus server
  • aws_access_key_id (string) – Your AWS Access Key ID
  • aws_secret_access_key (string) – Your AWS Secret Access Key
Return type:

boto.s3.connection.S3Connection

Returns:

A connection to Walrus

boto.init_logging()
boto.lookup(service, name)
boto.set_file_logger(name, filepath, level=20, format_string=None)
boto.set_stream_logger(name, level=10, format_string=None)
boto.storage_uri(uri_str, default_scheme='file', debug=0, validate=True, bucket_storage_uri_class=<class 'boto.storage_uri.BucketStorageUri'>)

Instantiate a StorageUri from a URI string.

Parameters:
  • uri_str (string) – URI naming bucket + optional object.
  • default_scheme (string) – default scheme for scheme-less URIs.
  • debug (int) – debug level to pass in to boto connection (range 0..2).
  • validate (bool) – whether to check for bucket name validity.
  • bucket_storage_uri_class (BucketStorageUri interface.) – Allows mocking for unit tests.

We allow validate to be disabled to allow caller to implement bucket-level wildcarding (outside the boto library; see gsutil).

Return type:boto.StorageUri subclass
Returns:StorageUri subclass for given URI.

uri_str must be one of the following formats:

  • gs://bucket/name
  • s3://bucket/name
  • gs://bucket
  • s3://bucket
  • filename

The last example uses the default scheme (‘file’, unless overridden)

boto.storage_uri_for_key(key)

Returns a StorageUri for the given key.

Parameters:key (boto.s3.key.Key or subclass) – URI naming bucket + optional object.

boto.connection

Handles basic connections to AWS

class boto.connection.AWSAuthConnection(host, 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, debug=0, https_connection_factory=None, path='/', provider='aws')
Parameters:
  • host (str) – The host to make the connection to
  • aws_access_key_id (str) – Your AWS Access Key ID (provided by Amazon). If none is specified, the value in your AWS_ACCESS_KEY_ID environmental variable is used.
  • aws_secret_access_key (str) – Your AWS Secret Access Key (provided by Amazon). If none is specified, the value in your AWS_SECRET_ACCESS_KEY environmental variable is used.
  • is_secure (boolean) – Whether the connection is over SSL
  • https_connection_factory (list or tuple) – A pair of an HTTP connection factory and the exceptions to catch. The factory should have a similar interface to L{httplib.HTTPSConnection}.
  • proxy (str) – Address/hostname for a proxy server
  • proxy_port (int) – The port to use when connecting over a proxy
  • proxy_user (str) – The username to connect with on the proxy
  • proxy_pass (str) – The password to use when connection over a proxy.
  • port (int) – The port to use to connect
access_key
aws_access_key_id
aws_secret_access_key
build_base_http_request(method, path, auth_path, params=None, headers=None, data='', host=None)
close()

(Optional) Close any open HTTP connections. This is non-destructive, and making a new request will open a connection again.

connection
get_http_connection(host, is_secure)
get_path(path='/')
get_proxy_auth_header()
gs_access_key_id
gs_secret_access_key
handle_proxy(proxy, proxy_port, proxy_user, proxy_pass)
make_request(method, path, headers=None, data='', host=None, auth_path=None, sender=None, override_num_retries=None)

Makes a request to the server, with stock multiple-retry logic.

new_http_connection(host, is_secure)
prefix_proxy_to_path(path, host=None)
proxy_ssl()
put_http_connection(host, is_secure, connection)
secret_key
server_name(port=None)
class boto.connection.AWSQueryConnection(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=None, debug=0, https_connection_factory=None, path='/')
APIVersion = ''
ResponseError

alias of BotoServerError

build_list_params(params, items, label)
get_list(action, params, markers, path='/', parent=None, verb='GET')
get_object(action, params, cls, path='/', parent=None, verb='GET')
get_status(action, params, path='/', parent=None, verb='GET')
get_utf8_value(value)
make_request(action, params=None, path='/', verb='GET')
class boto.connection.ConnectionPool(hosts, connections_per_host)
class boto.connection.HTTPRequest(method, protocol, host, port, path, auth_path, params, headers, body)

Represents an HTTP request.

Parameters:
  • method (string) – The HTTP method name, ‘GET’, ‘POST’, ‘PUT’ etc.
  • protocol (string) – The http protocol used, ‘http’ or ‘https’.
  • host (string) – Host to which the request is addressed. eg. abc.com
  • port (int) – port on which the request is being sent. Zero means unset, in which case default port will be chosen.
  • path (string) – URL path that is bein accessed.
  • path – The part of the URL path used when creating the authentication string.
  • params (dict) – HTTP url query parameters, with key as name of the param, and value as value of param.
  • headers (dict) – HTTP headers, with key as name of the header and value as value of header.
  • body (string) – Body of the HTTP request. If not present, will be None or empty string (‘’).
authorize(connection, **kwargs)

boto.exception

Exception classes - Subclassing allows you to check for specific errors

exception boto.exception.AWSConnectionError(reason, *args)

General error connecting to Amazon Web Services.

exception boto.exception.BotoClientError(reason, *args)

General Boto Client error (error accessing AWS)

exception boto.exception.BotoServerError(status, reason, body=None, *args)
endElement(name, value, connection)
startElement(name, attrs, connection)
class boto.exception.ConsoleOutput(parent=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
exception boto.exception.EC2ResponseError(status, reason, body=None)

Error in response from EC2.

endElement(name, value, connection)
startElement(name, attrs, connection)
exception boto.exception.EmrResponseError(status, reason, body=None, *args)

Error in response from EMR

exception boto.exception.FPSResponseError(status, reason, body=None, *args)
exception boto.exception.GSCopyError(status, reason, body=None, *args)

Error copying a key on GS.

exception boto.exception.GSCreateError(status, reason, body=None)

Error creating a bucket or key on GS.

exception boto.exception.GSDataError(reason, *args)

Error receiving data from GS.

exception boto.exception.GSPermissionsError(reason, *args)

Permissions error when accessing a bucket or key on GS.

exception boto.exception.GSResponseError(status, reason, body=None)

Error in response from GS.

exception boto.exception.InvalidAclError(message)

Exception raised when ACL XML is invalid.

exception boto.exception.InvalidUriError(message)

Exception raised when URI is invalid.

exception boto.exception.NoAuthHandlerFound

Is raised when no auth handlers were found ready to authenticate.

exception boto.exception.ResumableDownloadException(message, disposition)

Exception raised for various resumable download problems.

self.disposition is of type ResumableTransferDisposition.

class boto.exception.ResumableTransferDisposition
ABORT = 'ABORT'
ABORT_CUR_PROCESS = 'ABORT_CUR_PROCESS'
START_OVER = 'START_OVER'
WAIT_BEFORE_RETRY = 'WAIT_BEFORE_RETRY'
exception boto.exception.ResumableUploadException(message, disposition)

Exception raised for various resumable upload problems.

self.disposition is of type ResumableTransferDisposition.

exception boto.exception.S3CopyError(status, reason, body=None, *args)

Error copying a key on S3.

exception boto.exception.S3CreateError(status, reason, body=None)

Error creating a bucket or key on S3.

exception boto.exception.S3DataError(reason, *args)

Error receiving data from S3.

exception boto.exception.S3PermissionsError(reason, *args)

Permissions error when accessing a bucket or key on S3.

exception boto.exception.S3ResponseError(status, reason, body=None)

Error in response from S3.

exception boto.exception.SDBPersistenceError
exception boto.exception.SDBResponseError(status, reason, body=None, *args)

Error in responses from SDB.

exception boto.exception.SQSDecodeError(reason, message)

Error when decoding an SQS message.

exception boto.exception.SQSError(status, reason, body=None)

General Error on Simple Queue Service.

endElement(name, value, connection)
startElement(name, attrs, connection)
exception boto.exception.StorageCopyError(status, reason, body=None, *args)

Error copying a key on a storage service.

exception boto.exception.StorageCreateError(status, reason, body=None)

Error creating a bucket or key on a storage service.

endElement(name, value, connection)
exception boto.exception.StorageDataError(reason, *args)

Error receiving data from a storage service.

exception boto.exception.StoragePermissionsError(reason, *args)

Permissions error when accessing a bucket or key on a storage service.

exception boto.exception.StorageResponseError(status, reason, body=None)

Error in response from a storage service.

endElement(name, value, connection)
startElement(name, attrs, connection)
exception boto.exception.TooManyAuthHandlerReadyToAuthenticate

Is raised when there are more than one auth handler ready.

In normal situation there should only be one auth handler that is ready to authenticate. In case where more than one auth handler is ready to authenticate, we raise this exception, to prevent unpredictable behavior when multiple auth handlers can handle a particular case and the one chosen depends on the order they were checked.

boto.handler

class boto.handler.XmlHandler(root_node, connection)
characters(content)
endElement(name)
startElement(name, attrs)

boto.resultset

class boto.resultset.BooleanResult(marker_elem=None)
endElement(name, value, connection)
startElement(name, attrs, connection)
to_boolean(value, true_value='true')
class boto.resultset.ResultSet(marker_elem=None)

The ResultSet is used to pass results back from the Amazon services to the client. It is light wrapper around Python’s list class, with some additional methods for parsing XML results from AWS. Because I don’t really want any dependencies on external libraries, I’m using the standard SAX parser that comes with Python. The good news is that it’s quite fast and efficient but it makes some things rather difficult.

You can pass in, as the marker_elem parameter, a list of tuples. Each tuple contains a string as the first element which represents the XML element that the resultset needs to be on the lookout for and a Python class as the second element of the tuple. Each time the specified element is found in the XML, a new instance of the class will be created and popped onto the stack.

Variables:next_token (str) – A hash used to assist in paging through very long result sets. In most cases, passing this value to certain methods will give you another ‘page’ of results.
endElement(name, value, connection)
startElement(name, attrs, connection)
to_boolean(value, true_value='true')

boto.utils

Some handy utility functions used by several classes.

class boto.utils.AuthSMTPHandler(mailhost, username, password, fromaddr, toaddrs, subject)

This class extends the SMTPHandler in the standard Python logging module to accept a username and password on the constructor and to then use those credentials to authenticate with the SMTP server. To use this, you could add something like this in your boto config file:

[handler_hand07] class=boto.utils.AuthSMTPHandler level=WARN formatter=form07 args=(‘localhost’, ‘username’, ‘password’, 'from@abc‘, ['user1@abc‘, 'user2@xyz‘], ‘Logger Subject’)

Initialize the handler.

We have extended the constructor to accept a username/password for SMTP authentication.

emit(record)

Emit a record.

Format the record and send it to the specified addressees. It would be really nice if I could add authorization to this class without having to resort to cut and paste inheritance but, no.

class boto.utils.LRUCache(capacity)

A dictionary-like object that stores only a certain number of items, and discards its least recently used item when full.

>>> cache = LRUCache(3)
>>> cache['A'] = 0
>>> cache['B'] = 1
>>> cache['C'] = 2
>>> len(cache)
3
>>> cache['A']
0

Adding new items to the cache does not increase its size. Instead, the least recently used item is dropped:

>>> cache['D'] = 3
>>> len(cache)
3
>>> 'B' in cache
False

Iterating over the cache returns the keys, starting with the most recently used:

>>> for key in cache:
...     print key
D
A
C

This code is based on the LRUCache class from Genshi which is based on Mighty’s LRUCache from myghtyutils.util, written by Mike Bayer and released under the MIT license (Genshi uses the BSD License). See:

class boto.utils.Password(str=None, hashfunc=None)

Password object that stores itself as hashed. Hash defaults to SHA512 if available, MD5 otherwise.

Load the string from an initial value, this should be the raw hashed password.

hashfunc()

Returns a sha512 hash object; optionally initialized with a string

set(value)
class boto.utils.ShellCommand(command, wait=True, fail_fast=False, cwd=None)
getOutput()
getStatus()
output

The STDIN and STDERR output of the command

run(cwd=None)
setReadOnly(value)
status

The exit code for the command

boto.utils.canonical_string(method, path, headers, expires=None, provider=None)
boto.utils.fetch_file(uri, file=None, username=None, password=None)

Fetch a file based on the URI provided. If you do not pass in a file pointer a tempfile.NamedTemporaryFile, or None if the file could not be retrieved is returned. The URI can be either an HTTP url, or “s3://bucket_name/key_name”

boto.utils.find_class(module_name, class_name=None)
boto.utils.get_aws_metadata(headers, provider=None)
boto.utils.get_instance_metadata(version='latest', url='http://169.254.169.254')

Returns the instance metadata as a nested Python dictionary. Simple values (e.g. local_hostname, hostname, etc.) will be stored as string values. Values such as ancestor-ami-ids will be stored in the dict as a list of string values. More complex fields such as public-keys and will be stored as nested dicts.

boto.utils.get_instance_userdata(version='latest', sep=None, url='http://169.254.169.254')
boto.utils.get_ts(ts=None)
boto.utils.get_utf8_value(value)
boto.utils.guess_mime_type(content, deftype)

Description: Guess the mime type of a block of text :param content: content we’re finding the type of :type str:

Parameters:deftype – Default mime type
Return type:<type>:
Returns:<description>
boto.utils.merge_meta(headers, metadata, provider=None)
boto.utils.mklist(value)
boto.utils.notify(subject, body=None, html_body=None, to_string=None, attachments=None, append_instance_id=True)
boto.utils.parse_ts(ts)
boto.utils.pythonize_name(name, sep='_')
boto.utils.retry_url(url, retry_on_404=True, num_retries=10)
boto.utils.update_dme(username, password, dme_id, ip_address)

Update your Dynamic DNS record with DNSMadeEasy.com

boto.utils.write_mime_multipart(content, compress=False, deftype='text/plain', delimiter=':')

Description: :param content: A list of tuples of name-content pairs. This is used instead of a dict to ensure that scripts run in order :type list of tuples:

Parameters:
  • compress – Use gzip to compress the scripts, defaults to no compression
  • deftype – The type that should be assumed if nothing else can be figured out
  • delimiter – mime delimiter
Returns:

Final mime multipart

Return type:

str: