awslimitchecker.connectable module

class awslimitchecker.connectable.Connectable[source]

Bases: object

Mix-in helper class for connecting to AWS APIs. Centralizes logic of connecting via regions and/or STS.

__dict__ = dict_proxy({'__module__': 'awslimitchecker.connectable', '_get_sts_token': <function _get_sts_token at 0x7fa56cc00cf8>, 'connect': <function connect at 0x7fa56cc00c08>, '__dict__': <attribute '__dict__' of 'Connectable' objects>, 'credentials': None, '_boto3_connection_kwargs': <property object at 0x7fa56cc06050>, '__weakref__': <attribute '__weakref__' of 'Connectable' objects>, '__doc__': '\n Mix-in helper class for connecting to AWS APIs. Centralizes logic of\n connecting via regions and/or STS.\n ', 'connect_resource': <function connect_resource at 0x7fa56cc00c80>})
__module__ = 'awslimitchecker.connectable'
__weakref__

list of weak references to the object (if defined)

_boto3_connection_kwargs

Generate keyword arguments for boto3 connection functions. If self.account_id is None, this will just include region_name=self.region. Otherwise, call _get_sts_token() to get STS token credentials using boto3.STS.Client.assume_role and include those credentials in the return value.

Returns:keyword arguments for boto3 connection functions
Return type:dict
_get_sts_token()[source]

Assume a role via STS and return the credentials.

First connect to STS via boto3.client(), then assume a role using boto3.STS.Client.assume_role using self.account_id and self.account_role (and optionally self.external_id, self.mfa_serial_number, self.mfa_token). Return the resulting ConnectableCredentials object.

Returns:STS assumed role credentials
Return type:ConnectableCredentials
connect()[source]

Connect to an AWS API via boto3 low-level client and set self.conn to the boto3.client object (a botocore.client.* instance). If self.conn is not None, do nothing. This connects to the API name given by self.api_name.

Returns:None
connect_resource()[source]

Connect to an AWS API via boto3 high-level resource connection and set self.resource_conn to the boto3.resource object (a boto3.resources.factory.*.ServiceResource instance). If self.resource_conn is not None, do nothing. This connects to the API name given by self.api_name.

Returns:None
credentials = None
class awslimitchecker.connectable.ConnectableCredentials(creds_dict)[source]

Bases: object

boto’s (2.x) boto.sts.STSConnection.assume_role() returns a boto.sts.credentials.Credentials object, but boto3’s boto3.sts.STSConnection.assume_role just returns a dict. This class provides a compatible interface for boto3.

__dict__ = dict_proxy({'__dict__': <attribute '__dict__' of 'ConnectableCredentials' objects>, '__module__': 'awslimitchecker.connectable', '__weakref__': <attribute '__weakref__' of 'ConnectableCredentials' objects>, '__doc__': "\n boto's (2.x) :py:meth:`boto.sts.STSConnection.assume_role` returns a\n :py:class:`boto.sts.credentials.Credentials` object, but boto3's\n `boto3.sts.STSConnection.assume_role <https://boto3.readthedocs.org/en/\n latest/reference/services/sts.html#STS.Client.assume_role>`_ just returns\n a dict. This class provides a compatible interface for boto3.\n ", '__init__': <function __init__ at 0x7fa56cc00b18>})
__init__(creds_dict)[source]
__module__ = 'awslimitchecker.connectable'
__weakref__

list of weak references to the object (if defined)