"""
wrapper around Boto3 clients that caches a configured session
"""
import functools
import inspect
import typing
import boto3 # type: ignore
[docs]class AWSClient(object):
"""
wrapper around Boto3 clients that caches a configured session
"""
SERVICE_NAME: typing.Optional[str] = None
[docs] def __init__(self, *args: str, **kwargs: str):
self.session_args = inspect.signature(boto3.session.Session).bind(*args, **kwargs)
@functools.cached_property
def session(self) -> boto3.session.Session:
"""
Lazy-load and cache an appropriate AWS session client
"""
return boto3.session.Session(*self.session_args.args, **self.session_args.kwargs)
@functools.cached_property
def client(self) -> typing.Any:
"""
Lazy-load and cache an appropriate service client
"""
return self.session.client(self.SERVICE_NAME)