@@ -42,7 +42,7 @@ const getLocalHost = async () => {
4242 // Issue: https://github.com/localstack/aws-cdk-local/issues/78
4343 if ( hostname === "localhost" ) {
4444 try {
45- const options = { host : hostname , port : EDGE_PORT } ;
45+ const options = { host : hostname , port : EDGE_PORT } ;
4646 await checkTCPConnection ( options ) ;
4747 } catch ( e ) {
4848 hostname = "127.0.0.1" ;
@@ -131,7 +131,7 @@ const getTemplateBody = (params) => {
131131// small import util function
132132
133133const modulePrefix = "aws-cdk/node_modules" ;
134- const importLib = function importLib ( libPath ) {
134+ const importLib = function importLib ( libPath ) {
135135 try {
136136 return require ( path . join ( modulePrefix , libPath ) ) ;
137137 } catch ( exc ) {
@@ -176,7 +176,7 @@ const patchCdkToolkit = (CdkToolkit) => {
176176 const CdkToolkitClass = CdkToolkit . ToolkitInfo || CdkToolkit ;
177177 getMethods ( CdkToolkitClass . prototype ) . forEach ( ( meth ) => {
178178 const original = CdkToolkitClass . prototype [ meth ] ;
179- CdkToolkitClass . prototype [ meth ] = async function methFunc ( ...args ) {
179+ CdkToolkitClass . prototype [ meth ] = async function methFunc ( ...args ) {
180180 await setSdkOptions ( this . props . sdkProvider . sdkOptions ) ;
181181 return original . bind ( this ) . apply ( this , args ) ;
182182 } ;
@@ -185,14 +185,14 @@ const patchCdkToolkit = (CdkToolkit) => {
185185
186186const patchCurrentAccount = ( SDK ) => {
187187 const currentAccountOrig = SDK . prototype . currentAccount ;
188- SDK . prototype . currentAccount = async function currentAccount ( ) {
188+ SDK . prototype . currentAccount = async function currentAccount ( ) {
189189 const { config} = this ;
190190 await setSdkOptions ( config ) ;
191191 return currentAccountOrig . bind ( this ) ( ) ;
192192 } ;
193193
194194 const forceCredentialRetrievalOrig = SDK . prototype . forceCredentialRetrieval ;
195- SDK . prototype . forceCredentialRetrieval = function forceCredentialRetrieval ( ) {
195+ SDK . prototype . forceCredentialRetrieval = function forceCredentialRetrieval ( ) {
196196 if ( ! this . _credentials . getPromise ) {
197197 this . _credentials . getPromise = ( ) => this . _credentials ;
198198 }
@@ -205,9 +205,9 @@ const patchToolkitInfo = (ToolkitInfo) => {
205205 BUCKET_NAME_OUTPUT , BUCKET_DOMAIN_NAME_OUTPUT
206206 } = require ( "aws-cdk/lib/api/bootstrap/bootstrap-props" ) ;
207207
208- const setBucketUrl = function setBucketUrl ( object ) {
208+ const setBucketUrl = function setBucketUrl ( object ) {
209209 Object . defineProperty ( object , "bucketUrl" , {
210- async get ( ) {
210+ async get ( ) {
211211 const bucket = this . requireOutput ( BUCKET_NAME_OUTPUT ) ;
212212 const domain = this . requireOutput ( BUCKET_DOMAIN_NAME_OUTPUT ) || await getLocalHost ( ) ;
213213 return `https://${ domain . replace ( `${ bucket } .` , "" ) } :${ EDGE_PORT } /${ bucket } ` ;
@@ -240,19 +240,14 @@ const patchLambdaMounting = (CdkToolkit) => {
240240 // modify asset paths to enable local Lambda code mounting
241241
242242 const lookupLambdaForAsset = ( template , paramName ) => {
243- const result = Object . keys ( template . Resources ) .
244- map ( ( key ) => template . Resources [ key ] ) .
245- filter ( ( res ) => res . Type === "AWS::Lambda::Function" ) .
246- filter ( ( res ) => JSON . stringify ( res . Properties . Code . S3Key ) . includes ( paramName ) ) ;
243+ const result = Object . keys ( template . Resources ) . map ( ( key ) => template . Resources [ key ] ) . filter ( ( res ) => res . Type === "AWS::Lambda::Function" ) . filter ( ( res ) => JSON . stringify ( res . Properties . Code . S3Key ) . includes ( paramName ) ) ;
247244 const props = result [ 0 ] . Properties ;
248245 const funcName = props . FunctionName ;
249246 if ( funcName ) {
250247 return funcName ;
251248 }
252249 const attributes = [ "Handler" , "Runtime" , "Description" , "Timeout" , "MemorySize" , "Environment" ] ;
253- const valueToHash = attributes . map ( ( attr ) => props [ attr ] ) .
254- map ( ( val ) => typeof val === "object" ? JSON . stringify ( diff . canonicalize ( val ) ) : val ? val : "" ) .
255- join ( "|" ) ;
250+ const valueToHash = attributes . map ( ( attr ) => props [ attr ] ) . map ( ( val ) => typeof val === "object" ? JSON . stringify ( diff . canonicalize ( val ) ) : val ? val : "" ) . join ( "|" ) ;
256251 return md5 ( valueToHash ) ;
257252 } ;
258253
@@ -296,13 +291,13 @@ const patchLambdaMounting = (CdkToolkit) => {
296291 // symlink local Lambda assets if "cdklocal deploy" is called with LAMBDA_MOUNT_CODE=1
297292
298293 const deployStackOrig = deployStackMod . deployStack ;
299- deployStackMod . deployStack = function deployStack ( options ) {
294+ deployStackMod . deployStack = function deployStack ( options ) {
300295 options . sdk . cloudFormationOrig = options . sdk . cloudFormationOrig || options . sdk . cloudFormation ;
301296 const state = { } ;
302297 options . sdk . cloudFormation = ( ) => state . instance ;
303298 const cfn = state . instance = options . sdk . cloudFormationOrig ( ) ;
304299 cfn . createChangeSetOrig = cfn . createChangeSetOrig || cfn . createChangeSet ;
305- const createChangeSetAsync = async function createChangeSetAsync ( params ) {
300+ const createChangeSetAsync = async function createChangeSetAsync ( params ) {
306301 if ( LAMBDA_MOUNT_CODE ) {
307302 const template = deserializeStructure ( await getTemplateBody ( params ) ) ;
308303 symlinkLambdaAssets ( template , params . Parameters ) ;
@@ -319,7 +314,7 @@ const patchLambdaMounting = (CdkToolkit) => {
319314 const { FileAssetHandler} = importLib ( "cdk-assets/lib/private/handlers/files" ) ;
320315
321316 const handlerPublish = FileAssetHandler . prototype . publish ;
322- FileAssetHandler . prototype . publish = function publish ( ) {
317+ FileAssetHandler . prototype . publish = function publish ( ) {
323318 if ( LAMBDA_MOUNT_CODE && this . asset . destination && this . asset . source ) {
324319 if ( this . asset . source . packaging === "zip" ) {
325320 // skip uploading this asset - should get mounted via `__file__` into the Lambda container later on
@@ -332,7 +327,7 @@ const patchLambdaMounting = (CdkToolkit) => {
332327 // symlink local Lambda assets if "cdklocal synth" is called with LAMBDA_MOUNT_CODE=1
333328
334329 const assemblyOrig = CdkToolkit . prototype . assembly ;
335- CdkToolkit . prototype . assembly = async function assembly ( ) {
330+ CdkToolkit . prototype . assembly = async function assembly ( ) {
336331 const result = await assemblyOrig . bind ( this ) ( ) ;
337332 if ( LAMBDA_MOUNT_CODE ) {
338333 result . assembly . artifacts . forEach ( ( art ) => {
@@ -360,12 +355,9 @@ const patchSdk = (SDK, localEndpoint) => {
360355 getMethods ( SDK . prototype ) . forEach ( ( methodName ) => {
361356 if ( typeof SDK . prototype [ methodName ] === 'function' ) {
362357 const original = SDK . prototype [ methodName ] ;
363- SDK . prototype [ methodName ] = function methFunc ( ...args ) {
364- this . config = {
365- ...this . config ,
366- endpoint : localEndpoint ,
367- forcePathStyle : true ,
368- } ;
358+ SDK . prototype [ methodName ] = function methFunc ( ...args ) {
359+ this . config . endpoint = localEndpoint ;
360+ this . config . forcePathStyle = true ;
369361 return original . apply ( this , args ) ;
370362 } ;
371363 }
@@ -375,25 +367,25 @@ const patchSdk = (SDK, localEndpoint) => {
375367let sdkOverwritten = false ;
376368const patchSdkProvider = ( provider , SDK ) => {
377369 getMethods ( provider . SdkProvider . prototype ) . forEach ( ( methodName ) => {
378- if ( typeof provider . SdkProvider . prototype [ methodName ] === 'function' ) {
379- const original = provider . SdkProvider . prototype [ methodName ] ;
380- provider . SdkProvider . prototype [ methodName ] = async function methFunc ( ...args ) {
381- const localEndpoint = await getLocalEndpoint ( ) ;
382-
383- if ( ! sdkOverwritten ) {
384- // the goal is to support `SdkProvider.withAssumedRole`
385- // since it instantiates a different client (i.e. not from the SDK class)
386- this . requestHandler . endpoint = localEndpoint ;
387- this . requestHandler . forcePathStyle = true ;
388- // patch SDK class methods (mostly clients) to make sure the config that is created in the constructor
389- // is updated with the correct configuration
390- patchSdk ( SDK , localEndpoint ) ;
391- sdkOverwritten = true ;
392- }
393- return await original . apply ( this , args ) ;
394- } ;
370+ if ( typeof provider . SdkProvider . prototype [ methodName ] === 'function' ) {
371+ const original = provider . SdkProvider . prototype [ methodName ] ;
372+ provider . SdkProvider . prototype [ methodName ] = async function methFunc ( ...args ) {
373+ const localEndpoint = await getLocalEndpoint ( ) ;
374+
375+ if ( ! sdkOverwritten ) {
376+ // the goal is to support `SdkProvider.withAssumedRole`
377+ // since it instantiates a different client (i.e. not from the SDK class)
378+ this . requestHandler . endpoint = localEndpoint ;
379+ this . requestHandler . forcePathStyle = true ;
380+ // patch SDK class methods (mostly clients) to make sure the config that is created in the constructor
381+ // is updated with the correct configuration
382+ patchSdk ( SDK , localEndpoint ) ;
383+ sdkOverwritten = true ;
395384 }
396- }
385+ return await original . apply ( this , args ) ;
386+ } ;
387+ }
388+ }
397389 ) ;
398390} ;
399391
@@ -414,7 +406,7 @@ const patchPre_2_14 = () => {
414406 var provider = null ;
415407 try {
416408 provider = require ( "aws-cdk/lib/api/aws-auth" ) ;
417- } catch ( e ) {
409+ } catch ( e ) {
418410 if ( e . code == "MODULE_NOT_FOUND" ) {
419411 console . log ( e ) ;
420412 console . error ( "`aws-cdk` module NOT found! Have you tried adding it to your `NODE_PATH`?" ) ;
@@ -434,7 +426,7 @@ const patchPost_2_14 = () => {
434426 var lib = null ;
435427 try {
436428 lib = require ( "aws-cdk/lib" ) ;
437- } catch ( e ) {
429+ } catch ( e ) {
438430 if ( e . code == "MODULE_NOT_FOUND" ) {
439431 console . log ( e ) ;
440432 console . log ( "`aws-cdk` module NOT found! Have you tried to add it to your `NODE_PATH`?" ) ;
0 commit comments