or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bundling-configuration.mdindex.mdpackaging-systems.mdpython-functions.mdpython-layers.md
tile.json

tessl/npm-aws-cdk--aws-lambda-python-alpha

The CDK Construct Library for AWS Lambda in Python

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@aws-cdk/aws-lambda-python-alpha@2.214.x

To install, run

npx @tessl/cli install tessl/npm-aws-cdk--aws-lambda-python-alpha@2.214.0

index.mddocs/

AWS CDK Lambda Python Alpha

The AWS CDK Construct Library for AWS Lambda in Python provides constructs for deploying Python Lambda functions and layers with advanced packaging and bundling capabilities. It supports multiple Python dependency management systems and provides sophisticated Docker-based bundling for Lambda-compatible deployment packages.

Package Information

  • Package Name: @aws-cdk/aws-lambda-python-alpha
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @aws-cdk/aws-lambda-python-alpha
  • Stability: Experimental (Alpha)
  • Requirements: Docker (required for bundling)

Core Imports

import * as python from '@aws-cdk/aws-lambda-python-alpha';

Individual imports:

import { PythonFunction, PythonLayerVersion, BundlingOptions } from '@aws-cdk/aws-lambda-python-alpha';

Basic Usage

import * as python from '@aws-cdk/aws-lambda-python-alpha';
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';

// Basic Python function
const func = new python.PythonFunction(this, 'MyFunction', {
  entry: '/path/to/my/python/code', // Directory containing your Python code
  runtime: Runtime.PYTHON_3_8,
  index: 'main.py',      // Optional, defaults to 'index.py'
  handler: 'lambda_handler', // Optional, defaults to 'handler'
});

// Python layer with dependencies
const layer = new python.PythonLayerVersion(this, 'MyLayer', {
  entry: '/path/to/layer/code', // Directory with requirements.txt or other dependency files
  compatibleRuntimes: [Runtime.PYTHON_3_8, Runtime.PYTHON_3_9],
});

// Function using the layer
const funcWithLayer = new python.PythonFunction(this, 'FunctionWithLayer', {
  entry: '/path/to/function/code',
  runtime: Runtime.PYTHON_3_8,
  layers: [layer],
});

Architecture

The library is built around several key components:

  • PythonFunction: Main construct extending aws-cdk-lib Function for Python-specific deployment
  • PythonLayerVersion: Layer construct for shared Python dependencies and libraries
  • Bundling System: Docker-based packaging that auto-detects dependency managers (pip, Poetry, Pipenv, uv)
  • Packaging Engine: Handles different Python dependency management systems transparently
  • Docker Integration: Lambda-compatible containers for cross-platform dependency installation

The bundling process automatically:

  1. Detects dependency files (requirements.txt, poetry.lock, Pipfile.lock, uv.lock)
  2. Exports dependencies to pip-compatible format when needed
  3. Installs dependencies in Lambda-compatible Docker environment
  4. Packages code and dependencies for deployment

Capabilities

Python Lambda Functions

Core functionality for deploying Python Lambda functions with automatic dependency bundling and cross-platform compatibility.

class PythonFunction extends Function {
  static readonly PROPERTY_INJECTION_ID: string;
  constructor(scope: Construct, id: string, props: PythonFunctionProps);
}

interface PythonFunctionProps extends FunctionOptions {
  readonly entry: string;
  readonly runtime: Runtime;
  readonly index?: string;
  readonly handler?: string;
  readonly bundling?: BundlingOptions;
}

Python Functions

Python Lambda Layers

Shared dependency layers for Python Lambda functions with multi-runtime and multi-architecture support.

class PythonLayerVersion extends LayerVersion {
  static readonly PROPERTY_INJECTION_ID: string;
  constructor(scope: Construct, id: string, props: PythonLayerVersionProps);
}

interface PythonLayerVersionProps extends LayerVersionOptions {
  readonly entry: string;
  readonly compatibleRuntimes?: Runtime[];
  readonly compatibleArchitectures?: Architecture[];
  readonly bundling?: BundlingOptions;
}

Python Layers

Advanced Bundling Configuration

Comprehensive bundling options for custom Docker images, private repositories, and complex deployment scenarios.

interface BundlingOptions extends DockerRunOptions {
  readonly poetryIncludeHashes?: boolean;
  readonly poetryWithoutUrls?: boolean;
  readonly assetExcludes?: string[];
  readonly outputPathSuffix?: string;
  readonly image?: DockerImage;
  readonly buildArgs?: { [key: string]: string };
  readonly assetHashType?: AssetHashType;
  readonly assetHash?: string;
  readonly commandHooks?: ICommandHooks;
  readonly bundlingFileAccess?: BundlingFileAccess;
}

interface ICommandHooks {
  beforeBundling(inputDir: string, outputDir: string): string[];
  afterBundling(inputDir: string, outputDir: string): string[];
}

Bundling Configuration

Core Types

interface PoetryPackagingProps {
  readonly poetryIncludeHashes?: boolean;
  readonly poetryWithoutUrls?: boolean;
}

Additional Types

enum DependenciesFile {
  PIP = 'requirements.txt',
  POETRY = 'poetry.lock',  
  PIPENV = 'Pipfile.lock',
  UV = 'uv.lock',
  NONE = '',
}

interface PackagingProps {
  readonly dependenciesFile: DependenciesFile;
  readonly exportCommand?: string;
}

const DEPENDENCY_EXCLUDES: string[];
const BUNDLER_DEPENDENCIES_CACHE: string;

Note: The library uses automatic dependency detection and bundling. For advanced packaging scenarios and detailed information about the packaging system, see Packaging Systems.