From 3b64d62c1ece6ac2d1854b0bb3736f7827a6e63d Mon Sep 17 00:00:00 2001 From: FabrizioCafolla Date: Tue, 3 Oct 2023 18:10:30 +0200 Subject: [PATCH] fix(stacks): disable condition --- .../aws-lambda/newrelic-functions.ts | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/constructs/aws-lambda/newrelic-functions.ts b/src/constructs/aws-lambda/newrelic-functions.ts index d951741..c888291 100644 --- a/src/constructs/aws-lambda/newrelic-functions.ts +++ b/src/constructs/aws-lambda/newrelic-functions.ts @@ -66,14 +66,16 @@ export function addNewRelicLayer(scope: Construct, lambdaFunction: lambda.Functi export class NewRelicFunction extends Function { constructor(scope: Construct, id: string, props: FunctionNewRelicProps) { - const app_handler = props.handler; - const handler = 'newrelic_lambda_wrapper.handler'; + const disableNewRelic = props.disableNewRelic ?? false; - super(scope, id, { ...props, handler }); + if (disableNewRelic === true) { + super(scope, id, props); + } else { + const app_handler = props.handler; + const handler = 'newrelic_lambda_wrapper.handler'; - const disableNewRelic = props.disableNewRelic ?? false; + super(scope, id, { ...props, handler }); - if (disableNewRelic === false) { this.addNewRelicLayer(scope, { handler: app_handler, newRelicLayerName: props.newRelicLayerName, @@ -82,6 +84,7 @@ export class NewRelicFunction extends Function { newRelicwithExtensionSendLogs: props.newRelicwithExtensionSendLogs ?? true, }); } + } addNewRelicLayer(scope: Construct, props: NewRelicLayerProps) { @@ -91,14 +94,16 @@ export class NewRelicFunction extends Function { export class NewRelicFunctionNode extends FunctionNode { constructor(scope: Construct, id: string, props: FunctionNodeNewRelicProps) { - const app_handler = props.handler ?? 'index.handler'; - const handler = 'newrelic-lambda-wrapper.handler'; + const disableNewRelic = props.disableNewRelic ?? false; - super(scope, id, { ...props, handler }); + if (disableNewRelic === true) { + super(scope, id, props); + } else { + const app_handler = props.handler ?? 'index.handler'; + const handler = 'newrelic-lambda-wrapper.handler'; - const disableNewRelic = props.disableNewRelic ?? false; + super(scope, id, { ...props, handler }); - if (disableNewRelic === false) { this.addNewRelicLayer(scope, { handler: app_handler, newRelicLayerName: props.newRelicLayerName,