@@ -26,6 +26,7 @@ let iamClient: IAMClient | undefined;
2626
2727const inlinePolicyName = 'LambdaLiveDebuggerPolicy' ;
2828const layerName = 'LambdaLiveDebugger' ;
29+ const lldWrapperPath = '/opt/lld-wrapper' ;
2930
3031/**
3132 * Policy document to attach to the Lambda role
@@ -300,7 +301,16 @@ async function removeLayerFromLambda(functionName: string) {
300301 ) ;
301302 }
302303
303- const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger ( 'xxx' , 0 ) ;
304+ const initalExecWraper =
305+ environmentVariables . LLD_INITIAL_AWS_LAMBDA_EXEC_WRAPPER ;
306+
307+ const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger ( {
308+ // set dummy data, so we just get the list of environment variables
309+ functionId : 'xxx' ,
310+ timeout : 0 ,
311+ verbose : true ,
312+ initalExecWraper : 'test' ,
313+ } ) ;
304314
305315 // check if environment variables are set for each property
306316 for ( const [ key ] of Object . entries ( ddlEnvironmentVariables ) ) {
@@ -323,10 +333,22 @@ async function removeLayerFromLambda(functionName: string) {
323333 //remove environment variables
324334 for ( const [ key ] of Object . entries ( ddlEnvironmentVariables ) ) {
325335 if ( environmentVariables && environmentVariables [ key ] ) {
326- delete environmentVariables [ key ] ;
336+ if ( key === 'AWS_LAMBDA_EXEC_WRAPPER' ) {
337+ if ( environmentVariables [ key ] === lldWrapperPath ) {
338+ delete environmentVariables [ key ] ;
339+ } else {
340+ // do not remove the original AWS_LAMBDA_EXEC_WRAPPER that was set before LLD
341+ }
342+ } else {
343+ delete environmentVariables [ key ] ;
344+ }
327345 }
328346 }
329347
348+ if ( initalExecWraper ) {
349+ environmentVariables . AWS_LAMBDA_EXEC_WRAPPER = initalExecWraper ;
350+ }
351+
330352 Logger . verbose (
331353 'New environment variables' ,
332354 JSON . stringify ( environmentVariables , null , 2 ) ,
@@ -445,10 +467,24 @@ async function attachLayerToLambda(
445467 Logger . verbose ( 'Layer with the wrong version attached to the function' ) ;
446468 }
447469
448- const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger (
470+ // support for multiple internal Lambda extensions
471+ const initalExecWraper =
472+ environmentVariables . AWS_LAMBDA_EXEC_WRAPPER !== lldWrapperPath
473+ ? environmentVariables . AWS_LAMBDA_EXEC_WRAPPER
474+ : undefined ;
475+
476+ if ( initalExecWraper ) {
477+ Logger . warn (
478+ `[Function ${ functionName } ] Another internal Lambda extension is already attached to the function, which might cause unpredictable behavior.` ,
479+ ) ;
480+ }
481+
482+ const ddlEnvironmentVariables = getEnvironmentVarablesForDebugger ( {
449483 functionId,
450- initialTimeout ,
451- ) ;
484+ timeout : initialTimeout ,
485+ verbose : Configuration . config . verbose ,
486+ initalExecWraper,
487+ } ) ;
452488
453489 // check if environment variables are already set for each property
454490 for ( const [ key , value ] of Object . entries ( ddlEnvironmentVariables ) ) {
@@ -551,22 +587,36 @@ async function addPolicyToLambdaRole(functionName: string) {
551587
552588/**
553589 * Get the environment variables for the Lambda function
554- * @param functionId
555- * @param timeout
556- * @returns
557590 */
558- function getEnvironmentVarablesForDebugger (
559- functionId : string ,
560- timeout : number | undefined ,
561- ) : Record < string , string > {
562- return {
591+ function getEnvironmentVarablesForDebugger ( {
592+ functionId,
593+ timeout,
594+ verbose,
595+ initalExecWraper,
596+ } : {
597+ functionId : string ;
598+ timeout : number | undefined ;
599+ verbose : boolean | undefined ;
600+ initalExecWraper : string | undefined ;
601+ } ) : Record < string , string > {
602+ const env : Record < string , string > = {
563603 LLD_FUNCTION_ID : functionId ,
564- AWS_LAMBDA_EXEC_WRAPPER : '/opt/lld-wrapper' ,
604+ AWS_LAMBDA_EXEC_WRAPPER : lldWrapperPath ,
565605 LLD_DEBUGGER_ID : Configuration . config . debuggerId ,
566606 LLD_INITIAL_TIMEOUT : timeout ? timeout . toString ( ) : '-1' , // should never be negative
567607 LLD_OBSERVABLE_MODE : Configuration . config . observable ? 'true' : 'false' ,
568608 LLD_OBSERVABLE_INTERVAL : Configuration . config . interval . toString ( ) ,
569609 } ;
610+
611+ if ( initalExecWraper ) {
612+ env . LLD_INITIAL_AWS_LAMBDA_EXEC_WRAPPER = initalExecWraper ;
613+ }
614+
615+ if ( verbose ) {
616+ env . LLD_VERBOSE = 'true' ;
617+ }
618+
619+ return env ;
570620}
571621
572622/**
0 commit comments