Base Constructs¶
Base construct classes and environment-aware mixins.
base
¶
Base construct classes and mixins for environment-aware CDK constructs.
This module provides the foundational classes and mixins that enable environment-aware CDK constructs throughout the library.
Classes¶
EnvBaseConstructMixins
¶
Bases: EnvBaseMixins
Mixin class providing environment-aware utilities for CDK constructs.
This mixin extends EnvBaseMixins with CDK-specific functionality including resource naming, tagging, and IAM utilities.
Functions¶
add_tags
¶
Add tags to the construct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tags
|
Tag
|
Tags to add to the construct. |
()
|
normalize_construct_id
¶
Normalize a construct ID to fit within size constraints.
Replaces special characters with dashes and truncates long IDs by appending a hash suffix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
construct_id
|
str
|
The original construct ID. |
required |
max_size
|
int
|
Maximum allowed length. Defaults to 64. |
64
|
hash_size
|
int
|
Length of hash suffix for truncation. Defaults to 8. |
8
|
Returns:
| Type | Description |
|---|---|
str
|
The normalized construct ID. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_size is less than hash_size. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
get_construct_id
¶
Build a construct ID from name components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Name components to include in the construct ID. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
The constructed ID with environment prefix. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
get_child_id
¶
Build a child construct ID, avoiding duplicate env_base prefixes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
The parent construct scope. |
required |
*names
|
str
|
Name components for the child ID. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
The child construct ID. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
get_name_with_env
¶
Get a name prefixed with the environment base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
Name components to prefix. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
The environment-prefixed name. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
get_resource_name
¶
Get the full resource name with environment prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Union[ResourceNameBaseEnum, str]
|
The resource name or enum. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The fully qualified resource name. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
get_stack_of
¶
Get the stack containing a construct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
construct
|
Optional[Construct]
|
The construct to find the stack for. Defaults to self. |
None
|
Returns:
| Type | Description |
|---|---|
Stack
|
The CDK Stack containing the construct. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
as_construct
¶
Return this object as a Construct.
Returns:
| Type | Description |
|---|---|
Construct
|
This object cast as a Construct. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If this object is not a Construct instance. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
build_construct_id
classmethod
¶
Build a construct ID from environment base and name components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_base
|
EnvBase
|
The environment base configuration. |
required |
*names
|
str
|
Name components to include in the ID. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
The constructed ID string. |
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
add_managed_policies
classmethod
¶
Add managed policies to an IAM role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
role
|
Optional[IRole]
|
The IAM role to add policies to. |
required |
*managed_policies
|
Union[str, ManagedPolicy]
|
Managed policies to add, either by name or as ManagedPolicy objects. |
()
|
Source code in src/aibs_informatics_cdk_lib/constructs_/base.py
EnvBaseConstruct
¶
Bases: Construct, EnvBaseConstructMixins
Base construct class with environment awareness.
Provides a foundation for creating CDK constructs that are aware of the deployment environment and support automatic tagging.
Initialize an environment-aware construct.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
Construct
|
The parent construct scope. |
required |
id
|
Optional[str]
|
The construct ID. Defaults to class name if None. |
required |
env_base
|
EnvBase
|
The environment base configuration. |
required |