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(…)

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

resource(…)

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: str | None, service_name: Literal[s3], endpoint_url: str | None = None) mypy_boto3_s3.S3ServiceResource
resource(region: str | None, service_name: Literal[iam], endpoint_url: str | None = None) mypy_boto3_iam.IAMServiceResource
resource(region: str | None, service_name: Literal[ec2], endpoint_url: str | None = None) mypy_boto3_ec2.EC2ServiceResource

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

Parameters:

endpoint_url – AWS endpoint URL to use for the client. If not specified, a default is used.

client(region: str | None, service_name: Literal[ec2], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_ec2.EC2Client
client(region: str | None, service_name: Literal[iam], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_iam.IAMClient
client(region: str | None, service_name: Literal[s3], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_s3.S3Client
client(region: str | None, service_name: Literal[sts], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_sts.STSClient
client(region: str | None, service_name: Literal[sdb], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_sdb.SimpleDBClient
client(region: str | None, service_name: Literal[autoscaling], endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_autoscaling.AutoScalingClient

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

Parameters:
  • endpoint_url – AWS endpoint URL to use for the client. If not specified, a default is used.

  • config – Custom configuration to use for the client.

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: Literal[ec2], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_ec2.EC2Client
toil.lib.aws.session.client(service_name: Literal[iam], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_iam.IAMClient
toil.lib.aws.session.client(service_name: Literal[s3], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_s3.S3Client
toil.lib.aws.session.client(service_name: Literal[sts], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_sts.STSClient
toil.lib.aws.session.client(service_name: Literal[sdb], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_sdb.SimpleDBClient
toil.lib.aws.session.client(service_name: Literal[autoscaling], region_name: str | None = None, endpoint_url: str | None = None, config: botocore.client.Config | None = None) mypy_boto3_autoscaling.AutoScalingClient

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

Global alternative to AWSConnectionManager.

toil.lib.aws.session.resource(service_name: Literal[s3], region_name: str | None = None, endpoint_url: str | None = None) mypy_boto3_s3.S3ServiceResource
toil.lib.aws.session.resource(service_name: Literal[iam], region_name: str | None = None, endpoint_url: str | None = None) mypy_boto3_iam.IAMServiceResource
toil.lib.aws.session.resource(service_name: Literal[ec2], region_name: str | None = None, endpoint_url: str | None = None) mypy_boto3_ec2.EC2ServiceResource

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

Global alternative to AWSConnectionManager.