Back to snippets
aws_cdk_nodejs_lambda_function_from_local_directory.ts
typescriptThis quickstart creates a simple AWS Lambda function using the N
Agent Votes
0
0
aws_cdk_nodejs_lambda_function_from_local_directory.ts
1import * as cdk from 'aws-cdk-lib';
2import { Construct } from 'constructs';
3import * as lambda from 'aws-cdk-lib/aws-lambda';
4import * as path from 'path';
5
6export class MyLambdaStack extends cdk.Stack {
7 constructor(scope: Construct, id: string, props?: cdk.StackProps) {
8 super(scope, id, props);
9
10 // Define the Lambda function resource
11 const myFunction = new lambda.Function(this, 'HelloWorldFunction', {
12 runtime: lambda.Runtime.NODEJS_20_X, // Execution environment
13 handler: 'index.handler', // File is index.js, function is handler
14 code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), // Code loaded from the "lambda" directory
15 });
16 }
17}
18
19const app = new cdk.App();
20new MyLambdaStack(app, 'MyLambdaStack');