AWS CDK AWS Lambda Constructs (v1)

1.204.0 · deprecated · verified Thu Apr 16

This package provides the AWS Cloud Development Kit (CDK) constructs for defining AWS Lambda functions using Python. It belongs to the *deprecated* AWS CDK v1 ecosystem, specifically version 1.204.0. While functional, users are strongly encouraged to migrate to AWS CDK v2 (`aws-cdk-lib`) for ongoing support, new features, and a simplified module structure. The AWS CDK has a rapid release cadence, often multiple times a week for bug fixes and minor features, with larger feature releases typically weekly or bi-weekly.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic AWS Lambda function using `aws-cdk-aws-lambda` (v1) in Python. It creates a `cdk.Stack` and then adds a `lambda_.Function` with inline code. Ensure you have the AWS CDK v1 CLI and Python packages installed, and your AWS credentials configured, then run `cdk deploy` from your terminal in the directory where this code is saved (e.g., in `app.py`).

import os
from aws_cdk import (
    core as cdk, # For App, Stack
    aws_lambda as lambda_,
)
from constructs import Construct

class MyLambdaStack(cdk.Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        lambda_.Function(
            self, "MyHelloWorldFunction",
            runtime=lambda_.Runtime.PYTHON_3_9,
            handler="main.handler",
            code=lambda_.Code.from_inline(
                "import json\n"
                "def handler(event, context):\n"
                "    return {\n"
                "        'statusCode': 200,\n"
                "        'body': json.dumps('Hello from CDK Lambda (v1)!')\n"
                "    }"
            ),
            environment={"GREETING": os.environ.get('LAMBDA_GREETING', 'World')}
        )

# Instantiate the app and stack
app = cdk.App()
MyLambdaStack(app, "MyV1LambdaStack", env=cdk.Environment(
    account=os.environ.get('CDK_DEFAULT_ACCOUNT'),
    region=os.environ.get('CDK_DEFAULT_REGION')
))
app.synth()

view raw JSON →