Documentation Index
Fetch the complete documentation index at: https://mintlify.com/okruti-raghuraj/aws-1/llms.txt
Use this file to discover all available pages before exploring further.
LambdaStack is the application-layer CDK stack that the pipeline deploys after successfully synthesizing and self-mutating. While the pipeline stack defines how code gets delivered, LambdaStack defines what gets delivered — in this case, a serverless AWS Lambda function. It is instantiated inside MyPipelineAppStage so the pipeline can treat it as an atomic deployment unit.
Current State
The file lib/aws-cdk-pipeline-lambda-stack.ts ships as a fully commented-out template. This is intentional — it gives you a ready-to-use starting point without deploying real resources until you are ready to activate it.
aws-cdk-pipeline/lib/aws-cdk-pipeline-lambda-stack.ts
// import * as cdk from 'aws-cdk-lib';
// import { Construct } from 'constructs';
// import { Function, InlineCode, Runtime } from 'aws-cdk-lib/aws-lambda';
// export class LambdaStack extends cdk.Stack{
// constructor(scope: Construct , id: string , props?: cdk.StackProps){
// super(scope , id , props);
// new Function(this, 'lambdafunction' ,{
// runtime: Runtime.NODEJS_12_X,
// handler: 'index.handler',
// code: new InlineCode('exports.handler = _ => "Hello, CDK";')
// });
// }
// }
The class and its imports are commented out so the project compiles and synthesizes cleanly without actually creating a Lambda function. When you are ready to deploy the function, uncomment the entire file and wire the stack into MyPipelineAppStage.
Once you remove the comment markers the stack looks like this:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Function, InlineCode, Runtime } from 'aws-cdk-lib/aws-lambda';
export class LambdaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new Function(this, 'lambdafunction', {
runtime: Runtime.NODEJS_12_X,
handler: 'index.handler',
code: new InlineCode('exports.handler = _ => "Hello, CDK";')
});
}
}
This creates a single Lambda function with a tiny inline handler. The function returns the string "Hello, CDK" for any invocation, making it an ideal smoke-test target during pipeline validation.
Lambda Construct Properties
Runtime.NODEJS_12_X — specifies the Lambda execution environment. This controls the version of Node.js available to your function code at runtime.
'index.handler' — the entry-point for Lambda invocations. The format is <filename>.<exportedFunctionName>. With InlineCode, the virtual filename is always index, so index.handler maps to the exported handler function.
new InlineCode('exports.handler = _ => "Hello, CDK";') — embeds the function source directly in the CloudFormation template. This is convenient for small proof-of-concept functions. For any real workload, replace this with file-based or asset-based code (see below).
Runtime.NODEJS_12_X reached end-of-life and is deprecated in AWS Lambda. New functions using this runtime cannot be created in most regions. Replace it with a supported runtime before deploying:runtime: Runtime.NODEJS_18_X, // LTS — recommended
// or
runtime: Runtime.NODEJS_20_X, // Latest stable
Extending the Lambda with File-Based Code
For production workloads you will want to load function code from your repository rather than using an inline string. Replace InlineCode with Code.fromAsset and point it at a local directory:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { Function, Code, Runtime } from 'aws-cdk-lib/aws-lambda';
export class LambdaStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new Function(this, 'lambdafunction', {
runtime: Runtime.NODEJS_18_X,
handler: 'index.handler',
// Bundles everything in ./lambda/ into a deployment ZIP
code: Code.fromAsset('./lambda'),
});
}
}
Place your handler file at lambda/index.js (or lambda/index.ts if you add a bundler like esbuild). The CDK will automatically zip and upload the directory to S3 during cdk synth.
LambdaStack on its own is never deployed directly. It must be added to a cdk.Stage subclass — in this project that is MyPipelineAppStage. The stage is what you attach to the pipeline with pipeline.addStage(...), giving the pipeline full visibility into which stacks belong together in a single deployment wave.