toil.lib.aws.session

Module Contents

Classes

AWSConnectionManager

Class that represents a connection to AWS. Caches Boto 3 and Boto 2 objects

Functions

establish_boto3_session([region_name])

Get a Boto 3 session usable by the current thread.

client(service_name[, region_name, endpoint_url, config])

Get a Boto 3 client for a particular AWS service, usable by the current thread.

resource(service_name[, region_name, endpoint_url])

Get a Boto 3 resource for a particular AWS service, usable by the current thread.

Attributes

logger

toil.lib.aws.session.logger
class toil.lib.aws.session.AWSConnectionManager

Class that represents a connection to AWS. Caches Boto 3 and Boto 2 objects by region.

Access to any kind of item goes through the particular method for the thing you want (session, resource, service, Boto2 Context), and then you pass the region you want to work in, and possibly the type of thing you want, as arguments.

This class is intended to eventually enable multi-region clusters, where connections to multiple regions may need to be managed in the same provisioner.

We also support None for a region, in which case no region will be passed to Boto/Boto3. The caller is responsible for implementing e.g. TOIL_AWS_REGION support.

Since connection objects may not be thread safe (see <https://boto3.amazonaws.com/v1/documentation/api/1.14.31/guide/session.html#multithreading-or-multiprocessing-with-sessions>), one is created for each thread that calls the relevant lookup method.

session(region)

Get the Boto3 Session to use for the given region.

Parameters:

region (Optional[str])

Return type:

boto3.session.Session

resource(region, service_name, endpoint_url=None)

Get the Boto3 Resource to use with the given service (like ‘ec2’) in the given region.

Parameters:
  • endpoint_url (Optional[str]) – AWS endpoint URL to use for the client. If not specified, a default is used.

  • region (Optional[str])

  • service_name (str)

Return type:

boto3.resources.base.ServiceResource

client(region, service_name, endpoint_url=None, config=None)

Get the Boto3 Client to use with the given service (like ‘ec2’) in the given region.

Parameters:
  • endpoint_url (Optional[str]) – AWS endpoint URL to use for the client. If not specified, a default is used.

  • config (Optional[botocore.client.Config]) – Custom configuration to use for the client.

  • region (Optional[str])

  • service_name (str)

Return type:

botocore.client.BaseClient

boto2(region, service_name)

Get the connected boto2 connection for the given region and service.

Parameters:
  • region (Optional[str])

  • service_name (str)

Return type:

boto.connection.AWSAuthConnection

toil.lib.aws.session.establish_boto3_session(region_name=None)

Get a Boto 3 session usable by the current thread.

This function may not always establish a new session; it can be memoized.

Parameters:

region_name (Optional[str])

Return type:

boto3.Session

toil.lib.aws.session.client(service_name, region_name=None, endpoint_url=None, config=None)

Get a Boto 3 client for a particular AWS service, usable by the current thread.

Global alternative to AWSConnectionManager.

Parameters:
  • service_name (str)

  • region_name (Optional[str])

  • endpoint_url (Optional[str])

  • config (Optional[botocore.client.Config])

Return type:

botocore.client.BaseClient

toil.lib.aws.session.resource(service_name, region_name=None, endpoint_url=None)

Get a Boto 3 resource for a particular AWS service, usable by the current thread.

Global alternative to AWSConnectionManager.

Parameters:
  • service_name (str)

  • region_name (Optional[str])

  • endpoint_url (Optional[str])

Return type:

boto3.resources.base.ServiceResource