@@ -16,6 +16,13 @@ export class BaseStack extends cdk.Stack {
1616 constructor ( scope : Construct , id : string , props : cdk . StackProps ) {
1717 super ( scope , id , props ) ;
1818
19+ // Get layers once for the entire stack
20+ const extensionLayer = getExtensionLayer ( this ) ;
21+ const node20Layer = getNode20Layer ( this ) ;
22+ const python313Layer = getPython313Layer ( this ) ;
23+ const java21Layer = getJava21Layer ( this ) ;
24+ const dotnet8Layer = getDotnet8Layer ( this ) ;
25+
1926 // Node.js Lambda
2027 const nodeFunctionName = `${ id } -node-lambda` ;
2128 const nodeFunction = new lambda . Function ( this , nodeFunctionName , {
@@ -35,8 +42,8 @@ export class BaseStack extends cdk.Stack {
3542 logGroup : createLogGroup ( this , nodeFunctionName )
3643 } ) ;
3744 nodeFunction . addToRolePolicy ( defaultDatadogSecretPolicy ) ;
38- nodeFunction . addLayers ( getExtensionLayer ( this ) ) ;
39- nodeFunction . addLayers ( getNode20Layer ( this ) ) ;
45+ nodeFunction . addLayers ( extensionLayer ) ;
46+ nodeFunction . addLayers ( node20Layer ) ;
4047
4148 // Python Lambda
4249 const pythonFunctionName = `${ id } -python-lambda` ;
@@ -60,8 +67,8 @@ export class BaseStack extends cdk.Stack {
6067 logGroup : createLogGroup ( this , pythonFunctionName )
6168 } ) ;
6269 pythonFunction . addToRolePolicy ( defaultDatadogSecretPolicy ) ;
63- pythonFunction . addLayers ( getExtensionLayer ( this ) ) ;
64- pythonFunction . addLayers ( getPython313Layer ( this ) ) ;
70+ pythonFunction . addLayers ( extensionLayer ) ;
71+ pythonFunction . addLayers ( python313Layer ) ;
6572
6673 // Java Lambda
6774 const javaFunctionName = `${ id } -java-lambda` ;
@@ -82,8 +89,8 @@ export class BaseStack extends cdk.Stack {
8289 logGroup : createLogGroup ( this , javaFunctionName )
8390 } ) ;
8491 javaFunction . addToRolePolicy ( defaultDatadogSecretPolicy ) ;
85- javaFunction . addLayers ( getExtensionLayer ( this ) ) ;
86- javaFunction . addLayers ( getJava21Layer ( this ) ) ;
92+ javaFunction . addLayers ( extensionLayer ) ;
93+ javaFunction . addLayers ( java21Layer ) ;
8794
8895 // .NET Lambda
8996 const dotnetFunctionName = `${ id } -dotnet-lambda` ;
@@ -103,7 +110,7 @@ export class BaseStack extends cdk.Stack {
103110 logGroup : createLogGroup ( this , dotnetFunctionName )
104111 } ) ;
105112 dotnetFunction . addToRolePolicy ( defaultDatadogSecretPolicy ) ;
106- dotnetFunction . addLayers ( getExtensionLayer ( this ) ) ;
107- dotnetFunction . addLayers ( getDotnet8Layer ( this ) ) ;
113+ dotnetFunction . addLayers ( extensionLayer ) ;
114+ dotnetFunction . addLayers ( dotnet8Layer ) ;
108115 }
109116}
0 commit comments