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