Install any skill in seconds. Free to start, no credit card required.
Get Started Free →AWS SAM and CDK guidance for scaffolding, templating, deploying, and CI/CD of serverless applications on AWS.
Use this skill ↓78% 83%+4 ptsof test cases passed
Passed 19 of 23 test cases with the skill, and 18 of 23 without it.
3 of 3 safety checks passed
Not used yet
CDK provides specialized constructs for defining Lambda functions. Always prefer the runtime-specific L2 constructs (NodejsFunction, PythonFunction) over the base Function when available — they handle bundling automatically.
NodejsFunctionThe NodejsFunction construct bundles TypeScript/JavaScript with esbuild automatically. No separate build step needed.
import * as cdk from 'aws-cdk-lib';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Duration } from 'aws-cdk-lib';
export class MyStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const orderHandler = new NodejsFunction(this, 'OrderHandler', {
entry: 'lambda/order-handler.ts', // path to TypeScript entry file
handler: 'handler', // exported function name
runtime: lambda.Runtime.NODEJS_24_X,
architecture: lambda.Architecture.ARM_64, // ~20% cheaper than x86_64
memorySize: 512,
timeout: Duration.seconds(30),
tracing: lambda.Tracing.ACTIVE,
environment: {
TABLE_NAME: myTable.tableName, // reference, not hardcoded string
},
bundling: {
minify: true,
sourceMap: true,
externalModules: ['@aws-sdk/*'], // exclude AWS SDK (provided by runtime)
},
});
}
}
Entry auto-detection: If entry is omitted, CDK looks for {stack-filename}.{construct-id}.ts next to the stack file.
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.