main#

Extend the config_patterns.multi_env_json module to add more AWS project specific features.

class aws_ops_alpha.config.main.BaseEnv(s3uri_artifacts: Optional[str] = None, s3uri_docs: Optional[str] = None, aws_account_id: Optional[str] = None, aws_region: Optional[str] = None, s3uri_data: Optional[str] = None, project_name: Optional[str] = None, env_name: Optional[str] = None)[source]#

Extend the config_patterns.multi_env_json.BaseEnv class to add more AWS project specific config fields and methods.

Example:

import typing as T
import dataclasses

@dataclasses.dataclass
class Env(BaseEnv):
    username: T.Optional[str] = dataclasses.field(default=None)
    password: T.Optional[str] = dataclasses.field(default=None)
classmethod from_dict(data: dict)[source]#

Create an instance from a dict.

class aws_ops_alpha.config.main.BaseConfig(data: dict, secret_data: dict, Env: Type[T_BASE_ENV], EnvEnum: Type[BaseEnvEnum], version: str)[source]#

Extend the config_patterns.multi_env_json.BaseConfig class to add more AWS project specific methods.

Example:

import typing as T
import dataclasses

@dataclasses.dataclass
class Env(BaseEnv):
    username: T.Optional[str] = dataclasses.field(default=None)
    password: T.Optional[str] = dataclasses.field(default=None)

@dataclasses.dataclass
class Config(BaseConfig[Env]):
    @classmethod
    def get_current_env(cls) -> str:
        # your implementation here

    @property
    def sbx(self):
        return self.get_env("sbx")

    @property
    def tst(self):
        return self.get_env("tst")

    @property
    def stg(self):
        return self.get_env("stg")

    @property
    def prd(self):
        return self.get_env("prd")
classmethod smart_load(runtime: Runtime, env_name_enum_class: Union[BaseEnvNameEnum, Type[BaseEnvNameEnum]], env_class: Type[T_BASE_ENV], path_config_json: Optional[Path] = None, path_config_secret_json: Optional[Path] = None, boto_ses_factory: Optional[AbstractBotoSesFactory] = None)[source]#

If you use the recommended multi-environments config management strategy, you can use this function to load the config object.

  1. on local, we consider the local json file as the source of truth. We read

    config data from path_config_json and path_config_secret_json files.

  2. on ci, we won’t have the secret json file available, we read the non-sensitive

    config.json from git, figure out the aws ssm parameter name, then load config data from it.

Parameters:
  • runtime – the aws_ops_alpha.runtime.Runtime object.

  • env_name_enum_class – env name enumeration class, not the instance. a subclass of aws_ops_alpha.environment.BaseEnvNameEnum.

  • env_class – the aws_ops_alpha.config.define.main.BaseEnv subclass.

  • path_config_json – you need this parameter when loading data from local. it is where you store the non-sensitive config data json file.

  • path_config_secret_json – you need this parameter when loading data from local. it is where you store the sensitive config data json file.

  • boto_ses_factory – you need this parameter when loading data from AWS parameter store in CI.

classmethod smart_backup(runtime: Runtime, bsm_devops: BotoSesManager, env_name_enum_class: Union[BaseEnvNameEnum, Type[BaseEnvNameEnum]], env_class: Type[BaseEnv], version: str, path_config_json: Optional[Path] = None, path_config_secret_json: Optional[Path] = None, raise_error: bool = False) Tuple[S3Path, bool][source]#

Create a backup of the current production config data in S3. The version is the project semantic version x.y.z. The version file is immutable.

Parameters:
  • runtime – the aws_ops_alpha.runtime.Runtime object.

  • bsm_devops – boto session manager for devops account.

  • env_name_enum_class – env name enumeration class, not the instance. a subclass of aws_ops_alpha.environment.BaseEnvNameEnum.

  • env_class – the aws_ops_alpha.config.define.main.BaseEnv subclass.

  • version – the project semantic version x.y.z

  • path_config_json – you need this parameter when loading data from local. it is where you store the non-sensitive config data json file.

  • path_config_secret_json – you need this parameter when loading data from local. it is where you store the sensitive config data json file.

  • raise_error – if True, raises error when backup failed.