aws package

Subpackages

Submodules

aws.client module

aws.client.get_session(profile: Optional[str] = None) → botocore.session.Session[source]

Returns a new or cached botocore session for the AWS profile.

aws.client.get_client(profile: str, region: str, service: str) → botocore.client.BaseClient[source]

Returns a new or cached botocore service client for the AWS profile, region, and service.

Warns when a service is not available for a region, which means we need to update botocore or skip that call for that region.

aws.client.get_available_profiles(profile: Optional[str] = None) → Iterable[str][source]
aws.client.get_available_regions(profile: Optional[str] = None) → List[str][source]
aws.client.get_available_services(profile: Optional[str] = None) → Iterable[str][source]
aws.client.get_account_id(profile: str) → str[source]
aws.client.full_results(client: botocore.client.BaseClient, method: str, args: List[str], kwargs: Dict[str, Any]) → Dict[str, Any][source]

Returns JSON results for an AWS botocore call. Flattens paginated results (if any).

class aws.client.AWSAPICall(profile, region, service, method, args, kwargs)[source]

Bases: tuple

profile: Optional[str]

Alias for field number 0

region: Optional[str]

Alias for field number 1

service: Optional[str]

Alias for field number 2

method: Optional[str]

Alias for field number 3

args: List[str]

Alias for field number 4

kwargs: Dict[str, Any]

Alias for field number 5

aws.client.cache_key(call: aws.client.AWSAPICall) → str[source]

Returns the fullname (directory and filename) for an AWS API call.

>>> cache_key(default_call._replace(
... profile='profile',
... region='region',
... service='service_name',
... method='method_name',
... args=['arg1', 'arg2'],
... kwargs=dict(kwarg1=True)))
'pytest_aws/profile/region/service_name/method_name/9965c005f623cd9130dd5a6dbdee87de.json'
aws.client.get_aws_resource(service_name: str, method_name: str, call_args: List[str], call_kwargs: Dict[str, Any], cache: Optional[_pytest.cacheprovider.Cache], profiles: List[Optional[str]], regions: List[str], result_from_error: Optional[Callable[[Any, Any], Any]] = None, debug_calls: bool = False, debug_cache: bool = False) → Generator[Dict[str, Any], None, None][source]

Fetches and yields AWS API JSON responses for all profiles and regions (list params)

class aws.client.BotocoreClient(profiles: List[Optional[str]], regions: Optional[List[str]], cache: _pytest.cacheprovider.Cache, debug_calls: bool, debug_cache: bool, offline: bool)[source]

Bases: object

get_regions() → List[str][source]
get(service_name: str, method_name: str, call_args: List[str], call_kwargs: Dict[str, Any], profiles: Optional[List[Optional[str]]] = None, regions: Optional[List[str]] = None, result_from_error: Optional[Callable[[Any, Any], Any]] = None, do_not_cache: bool = False)aws.client.BotocoreClient[source]
values() → Iterable[Any][source]

Returns the wrapped value

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = []
>>> c.values()
[]
extract_key(key: str, default: Any = None)aws.client.BotocoreClient[source]

From an iterable of dicts returns the value with the given keys discarding other values:

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = [{'id': 1}, {'id': 2}]
>>> c.extract_key('id').results
[1, 2]

When the key does not exist it returns the second arg which defaults to None:

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = [{'id': 1}, {}]
>>> c.extract_key('id').results
[1, None]

Propagates the ‘__pytest_meta’ key to dicts and lists of dicts:

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = [{'Attrs': {'Name': 'Test'}, '__pytest_meta': {'meta': 'dict'}}]
>>> c.extract_key('Attrs').results
[{'Name': 'Test', '__pytest_meta': {'meta': 'dict'}}]
>>> c.results = [{'Tags': [{'Name': 'Test', 'Value': 'Tag'}], '__pytest_meta': {'meta': 'dict'}}]
>>> c.extract_key('Tags').results
[[{'Name': 'Test', 'Value': 'Tag', '__pytest_meta': {'meta': 'dict'}}]]

But not to primitives:

>>> c.results = [{'PolicyNames': ['P1', 'P2']}]
>>> c.extract_key('PolicyNames').results
[['P1', 'P2']]

Errors when the outer dict is missing a meta key:

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = [{'Attrs': {'Name': 'Test'}}]
>>> c.extract_key('Attrs')
Traceback (most recent call last):
...
KeyError: '__pytest_meta'
flatten()aws.client.BotocoreClient[source]

Flattens one level of a nested list:

>>> c = BotocoreClient([None], None, None, None, None, offline=True)
>>> c.results = [['A', 1], ['B']]
>>> c.flatten().values()
['A', 1, 'B']

Only works for a list of lists:

>>> c.results = [{'A': 1}, {'B': 2}]
>>> c.flatten().values()
Traceback (most recent call last):
...
TypeError: can only concatenate list (not "dict") to list
debug()aws.client.BotocoreClient[source]

aws.conftest module

aws.conftest.pytest_configure(config: _pytest.config.Config) → None[source]

Module contents