Skip to content

Commit 36ce84d

Browse files
authored
fix(lambda-nodejs): instantiating NodejsFunction without the entry property fails (#34498)
The [addition](8ee4427) of the `@propertyInjectable` decorator onto `NodejsFunction` breaks it because it alters the callstack, which is inspected inside the construct to automagically determine the entrypoint of the function. Closes #34486 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9a56a78 commit 36ce84d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

packages/aws-cdk-lib/aws-lambda-nodejs/lib/function.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Architecture } from '../../aws-lambda';
99
import * as lambda from '../../aws-lambda';
1010
import { Annotations, FeatureFlags } from '../../core';
1111
import { addConstructMetadata } from '../../core/lib/metadata-resource';
12-
import { propertyInjectable } from '../../core/lib/prop-injectable';
1312
import { LAMBDA_NODEJS_USE_LATEST_RUNTIME } from '../../cx-api';
1413

1514
/**
@@ -111,11 +110,7 @@ export interface NodejsFunctionProps extends lambda.FunctionOptions {
111110
/**
112111
* A Node.js Lambda function bundled using esbuild
113112
*/
114-
@propertyInjectable
115113
export class NodejsFunction extends lambda.Function {
116-
/** Uniquely identifies this class. */
117-
public static readonly PROPERTY_INJECTION_ID: string = 'aws-cdk-lib.aws-lambda-nodejs.NodejsFunction';
118-
119114
constructor(scope: Construct, id: string, props: NodejsFunctionProps = {}) {
120115
if (props.runtime && props.runtime.family !== lambda.RuntimeFamily.NODEJS) {
121116
throw new Error('Only `NODEJS` runtimes are supported.');

tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ const NOT_INJECTABLE_CLASSES = [
2424
"filePath": "packages/aws-cdk-lib/aws-lambda/lib/function-base.ts",
2525
"className": "LatestVersion"
2626
},
27+
// because this construct reflects on its own callstack, which gets changed
28+
// once the decorator is added. TODO - fix to consider the call layer added by the decorator.
29+
{
30+
"filePath": "packages/aws-cdk-lib/aws-lambda-nodejs/lib/function.ts",
31+
"className": "NodejsFunction"
32+
},
2733
]
2834

2935
interface ResourceClass {

0 commit comments

Comments
 (0)