@@ -18,7 +18,6 @@ import {
1818 Code
1919} from "aws-cdk-lib/aws-lambda"
2020import { CfnLogGroup , CfnSubscriptionFilter , LogGroup } from "aws-cdk-lib/aws-logs"
21- import path from "path"
2221
2322export interface LambdaFunctionProps {
2423 readonly stackName : string
@@ -29,6 +28,7 @@ export interface LambdaFunctionProps {
2928 readonly additionalPolicies ?: Array < IManagedPolicy >
3029 readonly logRetentionInDays : number
3130 readonly logLevel : string
31+ readonly dependencyLocation ?: string
3232}
3333
3434// Lambda Insights layer for enhanced monitoring
@@ -116,11 +116,15 @@ export class LambdaFunction extends Construct {
116116 managedPolicies : requiredPolicies
117117 } )
118118
119- const dependencyLayer = new LayerVersion ( this , "DependencyLayer" , {
120- removalPolicy : RemovalPolicy . DESTROY ,
121- code : Code . fromAsset ( path . join ( props . packageBasePath , ".dependencies" ) ) ,
122- compatibleArchitectures : [ Architecture . X86_64 ]
123- } )
119+ const layers = [ insightsLambdaLayer ]
120+ if ( props . dependencyLocation ) {
121+ const dependencyLayer = new LayerVersion ( this , "DependencyLayer" , {
122+ removalPolicy : RemovalPolicy . DESTROY ,
123+ code : Code . fromAsset ( props . dependencyLocation ) ,
124+ compatibleArchitectures : [ Architecture . X86_64 ]
125+ } )
126+ layers . push ( dependencyLayer )
127+ }
124128
125129 // Create Lambda function with Python runtime and monitoring
126130 const lambdaFunction = new LambdaFunctionResource ( this , props . functionName , {
@@ -129,14 +133,14 @@ export class LambdaFunction extends Construct {
129133 timeout : Duration . seconds ( 50 ) ,
130134 architecture : Architecture . X86_64 ,
131135 handler : props . handler ,
132- code : Code . fromAsset ( path . join ( props . packageBasePath , "app" ) ) ,
136+ code : Code . fromAsset ( props . packageBasePath ) ,
133137 role,
134138 environment : {
135139 ...props . environmentVariables ,
136140 POWERTOOLS_LOG_LEVEL : props . logLevel
137141 } ,
138142 logGroup,
139- layers : [ insightsLambdaLayer , dependencyLayer ]
143+ layers : layers
140144 } )
141145
142146 // Suppress CFN guard rules for Lambda function
0 commit comments