Skip to content

Stacks Module

Stack base classes with environment configuration support.

base

Base stack classes for environment-aware CDK stacks.

This module provides the foundational stack classes that enable environment-aware deployments with automatic tagging and resource naming.

Classes

EnvBaseStackMixins

Bases: EnvBaseConstructMixins

Mixin class for environment-aware stack functionality.

Inherits all functionality from EnvBaseConstructMixins for use in stacks.

EnvBaseStack

EnvBaseStack(
    scope: Construct,
    id: str | None,
    env_base: EnvBase,
    env: Environment | None = None,
    **kwargs
)

Bases: Stack, EnvBaseStackMixins

Base stack class with environment awareness.

Provides automatic tagging with environment information and environment-specific removal policies.

Initialize an environment-aware stack.

Parameters:

Name Type Description Default
scope Construct

The parent construct scope.

required
id Optional[str]

The stack ID. Auto-generated if None.

required
env_base EnvBase

The environment base configuration.

required
env Optional[Environment]

AWS environment settings.

None
**kwargs

Additional arguments passed to cdk.Stack.

{}
Source code in src/aibs_informatics_cdk_lib/stacks/base.py
def __init__(
    self,
    scope: constructs.Construct,
    id: str | None,
    env_base: EnvBase,
    env: cdk.Environment | None = None,
    **kwargs,
) -> None:
    """Initialize an environment-aware stack.

    Args:
        scope (constructs.Construct): The parent construct scope.
        id (Optional[str]): The stack ID. Auto-generated if None.
        env_base (EnvBase): The environment base configuration.
        env (Optional[cdk.Environment]): AWS environment settings.
        **kwargs: Additional arguments passed to cdk.Stack.
    """
    super().__init__(
        scope,
        id or env_base.get_construct_id(str(self.__class__)),
        env=env,
        **kwargs,
    )
    self.env_base = env_base
    self.add_tags(*self.stack_tags)
Functions

Functions

get_all_stacks

get_all_stacks(scope: Construct) -> list[Stack]

Get all CDK stacks from a construct scope.

Parameters:

Name Type Description Default
scope Construct

The construct scope to search.

required

Returns:

Type Description
list[Stack]

List of all Stack children in the scope.

Source code in src/aibs_informatics_cdk_lib/stacks/base.py
def get_all_stacks(scope: constructs.Construct) -> list[cdk.Stack]:
    """Get all CDK stacks from a construct scope.

    Args:
        scope (constructs.Construct): The construct scope to search.

    Returns:
        List of all Stack children in the scope.
    """
    children = scope.node.children
    return [cast(cdk.Stack, child) for child in children if isinstance(child, cdk.Stack)]

add_stack_dependencies

add_stack_dependencies(
    source_stack: Stack, dependent_stacks: list[Stack]
)

Add dependencies between stacks.

Makes the dependent stacks depend on the source stack, ensuring proper deployment order.

Parameters:

Name Type Description Default
source_stack Stack

The stack that others depend on.

required
dependent_stacks List[Stack]

Stacks that depend on the source.

required
Source code in src/aibs_informatics_cdk_lib/stacks/base.py
def add_stack_dependencies(source_stack: cdk.Stack, dependent_stacks: list[cdk.Stack]):
    """Add dependencies between stacks.

    Makes the dependent stacks depend on the source stack,
    ensuring proper deployment order.

    Args:
        source_stack (cdk.Stack): The stack that others depend on.
        dependent_stacks (List[cdk.Stack]): Stacks that depend on the source.
    """
    for dependent_stack in dependent_stacks:
        dependent_stack.add_dependency(source_stack)