Smarter AWS Base Helper Class

class smarter.common.helpers.aws.aws.AWSBase(aws_access_key_id=None, aws_secret_access_key=None, aws_region=None, aws_profile=None, shared_resource_identifier=None, environment=None, environment_domain=None, root_domain=None, debug_mode=False, init_info=None)[source]

Bases: SmarterHelperMixin

Provides a foundational interface for interacting with AWS services in a secure, consistent, and environment-aware manner.

This base class is responsible for initializing and managing AWS connections, ensuring that credentials and sessions are established only when the application is in a ready state. It supports multiple authentication strategies, including IAM role-based security (for environments like AWS Lambda), AWS profiles, and direct access key credentials. The class automatically detects the execution environment and adapts its behavior accordingly, such as recognizing when it is running inside AWS infrastructure.

AWSBase also implements logic to determine whether the current environment is a recognized and authorized Smarter environment, which is critical for safely creating or modifying billable AWS resources. It provides mechanisms for reformatting and validating domain names, particularly transforming localhost or development domains into proxy domains compatible with AWS Route53 and Kubernetes, thereby supporting seamless local development and cloud deployment.

The class exposes properties and methods for accessing AWS account identity, region, authentication sources, and session objects, as well as utility functions for domain validation and environment-specific configuration. It includes robust logging and error handling to facilitate debugging and operational transparency. By centralizing AWS connection logic and environment checks, AWSBase enables derived helper classes to focus on service-specific functionality while maintaining consistent security and configuration practices across the codebase.

LOCAL_HOSTS = ['localhost', '127.0.0.1', 'localhost:9357', '127.0.0.1:9357', 'testserver']
__init__(aws_access_key_id=None, aws_secret_access_key=None, aws_region=None, aws_profile=None, shared_resource_identifier=None, environment=None, environment_domain=None, root_domain=None, debug_mode=False, init_info=None)[source]

Note: this needs to exist.

something in the Python MRO requires it, even if it does nothing. If you remove this, you will get a mysterious error about something downstream expecting exactly one object.

property authentication_credentials_are_initialized: bool

Are aws authentication settings initialized? True if we have enoug information to try to connect to AWS. False otherwise.

Returns:

True if initialized

Return type:

bool

property authentication_credentials_state: str

Return formatted ready state.

Returns:

formatted ready state

Return type:

str

property aws_access_key_id: str | None

AWS access key id

Returns:

AWS access key id

Return type:

Optional[str]

property aws_access_key_id_source: str | None

AWS access key id source

Returns:

AWS access key id source

Return type:

Optional[str]

property aws_account_id: str | None

AWS account id

Returns:

AWS account id

Return type:

Optional[str]

property aws_auth: dict[str, str | None]

AWS authentication

Returns:

AWS authentication details

Return type:

dict[str, Optional[str]]

property aws_iam_arn: str | None

AWS IAM ARN

Returns:

AWS IAM ARN (Amazon Resource Name)

Return type:

Optional[str]

property aws_is_configured: bool

Return True if AWS is configured.

Returns:

True if AWS is configured

Return type:

bool

property aws_profile: str | None

AWS profile

Returns:

AWS profile

Return type:

Optional[str]

property aws_region: str | None

AWS region

Returns:

AWS region (e.g. ‘us-west-2’)

Return type:

Optional[str]

property aws_secret_access_key: str | None

AWS secret access key

Returns:

AWS secret access key

Return type:

Optional[str]

property aws_secret_access_key_source: str | None

AWS secret access key source :return: AWS secret access key source :rtype: Optional[str]

property aws_session: Session | None

AWS session

Returns:

boto3 AWS session

Return type:

Optional[boto3.Session]

property client

Return the AWS client

Returns:

boto3 client instance

Return type:

a child of boto3.client

property client_type: str | None

Return the AWS client type.

Returns:

AWS client type

Return type:

Optional[str]

property debug_mode: bool

Debug mode

Returns:

debug mode

Return type:

bool

domain_resolver(domain)[source]

Validate the domain and swap out localhost for the proxy domain.

Parameters:

domain (str) – domain to validate

Return type:

str

property environment: str

Return the environment.

Returns:

environment

Return type:

str

property environment_api_domain: str

we need to rebuild these in order to reformat the localhost domain into a proxy domain that will work with AWS Route53 and Kubernetes

Returns:

environment API domain

Return type:

str

property environment_domain: str

we need to rebuild these in order to reformat the localhost domain into a proxy domain that will work with AWS Route53 and Kubernetes

Returns:

environment domain

Return type:

str

property formatted_class_name: str

Return formatted class name.

Returns:

formatted class name

Return type:

str

property identity: dict | None

Return the AWS identity for the current session.

This property retrieves the identity information associated with the current AWS credentials, including the user ID, AWS account number, and IAM ARN. The identity is fetched using the AWS Security Token Service (STS) and is cached for subsequent calls.

Returns:

A dictionary containing AWS identity details, or None if not available.

Return type:

Optional[dict]

Example output:

{
    "UserId": "AIDARKEXDU3E7KD3L3CRF",
    "Account": "090511222473",
    "Arn": "arn:aws:iam::090511222473:user/mcdaniel",
    "ResponseMetadata": {
        "RequestId": "4d20b844-7e75-4980-9e92-ca0867b24387",
        "HTTPStatusCode": 200,
        "HTTPHeaders": {
            "x-amzn-requestid": "4d20b844-7e75-4980-9e92-ca0867b24387",
            "x-amz-sts-extended-request-id": "MTp1cy1lYXN0LTI6UzoxNzYzNTc5NjUyMzA0OlI6MVFkeG8yZ1Q=",
            "content-type": "text/xml",
            "content-length": "405",
            "date": "Wed, 19 Nov 2025 19:14:12 GMT"
        },
        "RetryAttempts": 0
    }
}
property is_aws_deployed: bool

Return True if we’re running inside of AWS Lambda.

Returns:

True if running inside AWS Lambda

Return type:

bool

property ready: bool

Return True if we’re working with a known Smarter environment, and we consider it safe to create billable resources in AWS.

Returns:

True if ready

Return type:

bool

property root_domain: str

Return the root domain.

Returns:

root domain

Return type:

str

property shared_resource_identifier: str | None

Return the shared resource identifier.

Returns:

shared resource identifier

Return type:

Optional[str]

property version: str[source]

Return the version.

Returns:

boto3 version

Return type:

str