Assets¶
Lambda function and Docker image asset constructs.
assets
¶
Modules¶
code_asset
¶
Classes¶
CodeAsset
dataclass
¶
CodeAsset(
asset_name: str,
asset_props: AssetProps,
default_runtime: Runtime,
supported_runtimes: Sequence[Runtime] | None = None,
environment: Mapping[str, str] | None = None,
)
create_py_code_asset
classmethod
¶create_py_code_asset(
path: Path,
context_path: Path | None,
requirements_file: Path | None = None,
includes: Sequence[str] | None = None,
excludes: Sequence[str] | None = None,
runtime: Runtime = PYTHON_3_11,
platform: str | None = "linux/amd64",
environment: Mapping[str, str] | None = None,
use_uv: bool = False,
) -> CodeAsset
Create and bundle a Python Lambda code asset
This factory method prepares a Lambda code asset whose source may live in a subdirectory of a larger repository. It computes a stable hash (excluding common Python / build artifacts) to maximize CDK asset caching, then leverages CDK's Docker bundling to install dependencies into /asset-output so they are packaged alongside the function code.
Dependency installation strategies
- Standard pip (default): Installs either the provided requirements file or the local package (.) into /asset-output.
- uv (if use_uv=True): Uses uv for faster, deterministic resolution. If a requirements_file is supplied it is installed directly; otherwise uv export produces a frozen requirements file which is then installed.
Private Git dependencies
The host's ~/.ssh directory is mounted read‑only into the bundling container so that private repositories referenced in dependency specifications (e.g., git+ssh URLs) can be resolved. Diagnostic SSH output (ssh -vT git@github.com) is executed to aid debugging but does not fail the build.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the Python project or module root you want to package (the leaf containing setup.cfg, pyproject.toml, requirements, or the code itself). |
required |
context_path
|
Optional[Path]
|
Root directory used as the asset's source context (often the monorepo root). If None, defaults to path. Everything under this directory (minus excluded patterns) is made available during bundling so that relative/local path dependencies can resolve correctly. |
required |
requirements_file
|
Optional[Path]
|
Path to a requirements file (e.g., requirements.txt). If provided:
* pip mode: installs with pip -r |
None
|
includes
|
Optional[Sequence[str]]
|
Additional glob patterns to explicitly include when generating the asset hash. Useful for forcing hash sensitivity to files that might otherwise be excluded. |
None
|
excludes
|
Optional[Sequence[str]]
|
Additional glob patterns to exclude (beyond built-in Python / tooling ignores) for hashing and packaging. Helps reduce asset size and improve cache hits. |
None
|
runtime
|
Runtime
|
Lambda runtime whose bundling image will be used (default: PYTHON_3_11). |
PYTHON_3_11
|
platform
|
Optional[str]
|
Docker platform string (e.g., linux/amd64) to enforce architecture consistency when building on heterogeneous hosts (e.g., Apple Silicon). |
'linux/amd64'
|
environment
|
Optional[Mapping[str, str]]
|
Default environment variables to associate with the resulting CodeAsset (may be applied when the asset is used in Lambda functions). |
None
|
use_uv
|
bool
|
If True, use uv for dependency resolution and installation; otherwise fall back to pip. |
False
|
Returns:
| Type | Description |
|---|---|
CodeAsset
|
A new instance encapsulating the bundled Python code and dependencies. |
Source code in src/aibs_informatics_cdk_lib/constructs_/assets/code_asset.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
code_asset_definitions
¶
Classes¶
AssetsMixin
¶
resolve_repo_path
classmethod
¶Resolves the repo path from the environment or clones the repo from the url
This method is useful to quickly swapping between locally modified changes and the remote repo.
This should typically be used in the context of defining a code asset for a static name (e.g. AIBS_INFORMATICS_AWS_LAMBDA). You can then use the env var option to point to a local repo path for development.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_url
|
str
|
The git repo url. This is required. If the repo path is not in the environment, the repo will be cloned from this url. |
required |
repo_path_env_var
|
Optional[str]
|
The environment variable that contains the repo path or alternative repo url. This is optional. This is useful for local development. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path to the repo |
Source code in src/aibs_informatics_cdk_lib/constructs_/assets/code_asset_definitions.py
AIBSInformaticsCodeAssets
¶
AIBSInformaticsCodeAssets(
scope: Construct,
construct_id: str,
env_base: EnvBase,
runtime: Runtime | None = None,
aibs_informatics_aws_lambda_repo: str | None = None,
)
Bases: Construct, AssetsMixin
Source code in src/aibs_informatics_cdk_lib/constructs_/assets/code_asset_definitions.py
AIBS_INFORMATICS_AWS_LAMBDA
¶AIBS_INFORMATICS_AWS_LAMBDA() -> CodeAsset
Returns a NEW code asset for aibs-informatics-aws-lambda
Returns:
| Type | Description |
|---|---|
CodeAsset
|
The code asset |
Source code in src/aibs_informatics_cdk_lib/constructs_/assets/code_asset_definitions.py
AIBSInformaticsDockerAssets
¶
AIBSInformaticsDockerAssets(
scope: Construct,
construct_id: str,
env_base: EnvBase,
aibs_informatics_aws_lambda_repo: str | None = None,
)
Bases: Construct, AssetsMixin
Source code in src/aibs_informatics_cdk_lib/constructs_/assets/code_asset_definitions.py
AIBS_INFORMATICS_AWS_LAMBDA
¶Returns a NEW docker asset for aibs-informatics-aws-lambda
Returns:
| Type | Description |
|---|---|
DockerImageAsset
|
aws_ecr_assets.DockerImageAsset: The docker asset |