@@ -404,20 +404,11 @@ var CustomResourceHandler = class {
404
404
}
405
405
async handle ( ) {
406
406
try {
407
- console . log ( `Event: ${ JSON . stringify ( { ...this . event , ResponseURL : "..." } ) } ` ) ;
408
407
const response = await this . processEvent ( this . event . ResourceProperties ) ;
409
- console . log ( `Event output : ${ JSON . stringify ( response ) } ` ) ;
410
- await this . respond ( {
411
- status : "SUCCESS" ,
412
- reason : "OK" ,
413
- data : response
414
- } ) ;
408
+ return response ;
415
409
} catch ( e ) {
416
410
console . log ( e ) ;
417
- await this . respond ( {
418
- status : "FAILED" ,
419
- reason : e . message ?? "Internal Error"
420
- } ) ;
411
+ throw e ;
421
412
} finally {
422
413
clearTimeout ( this . timeout ) ;
423
414
}
@@ -479,7 +470,8 @@ var AssertionHandler = class extends CustomResourceHandler {
479
470
matchResult . finished ( ) ;
480
471
if ( matchResult . hasFailed ( ) ) {
481
472
result = {
482
- data : JSON . stringify ( {
473
+ failed : true ,
474
+ assertion : JSON . stringify ( {
483
475
status : "fail" ,
484
476
message : [
485
477
...matchResult . toHumanStrings ( ) ,
@@ -488,11 +480,11 @@ var AssertionHandler = class extends CustomResourceHandler {
488
480
} )
489
481
} ;
490
482
if ( request2 . failDeployment ) {
491
- throw new Error ( result . data ) ;
483
+ throw new Error ( result . assertion ) ;
492
484
}
493
485
} else {
494
486
result = {
495
- data : JSON . stringify ( {
487
+ assertion : JSON . stringify ( {
496
488
status : "success"
497
489
} )
498
490
} ;
@@ -562,7 +554,10 @@ function flatten(object) {
562
554
{ } ,
563
555
...function _flatten ( child , path = [ ] ) {
564
556
return [ ] . concat ( ...Object . keys ( child ) . map ( ( key ) => {
565
- const childKey = Buffer . isBuffer ( child [ key ] ) ? child [ key ] . toString ( "utf8" ) : child [ key ] ;
557
+ let childKey = Buffer . isBuffer ( child [ key ] ) ? child [ key ] . toString ( "utf8" ) : child [ key ] ;
558
+ if ( typeof childKey === "string" ) {
559
+ childKey = isJsonString ( childKey ) ;
560
+ }
566
561
return typeof childKey === "object" && childKey !== null ? _flatten ( childKey , path . concat ( [ key ] ) ) : { [ path . concat ( [ key ] ) . join ( "." ) ] : childKey } ;
567
562
} ) ) ;
568
563
} ( object )
@@ -572,6 +567,9 @@ var AwsApiCallHandler = class extends CustomResourceHandler {
572
567
async processEvent ( request2 ) {
573
568
const AWS = require ( "aws-sdk" ) ;
574
569
console . log ( `AWS SDK VERSION: ${ AWS . VERSION } ` ) ;
570
+ if ( ! Object . prototype . hasOwnProperty . call ( AWS , request2 . service ) ) {
571
+ throw Error ( `Service ${ request2 . service } does not exist in AWS SDK version ${ AWS . VERSION } .` ) ;
572
+ }
575
573
const service = new AWS [ request2 . service ] ( ) ;
576
574
const response = await service [ request2 . api ] ( request2 . parameters && decode ( request2 . parameters ) ) . promise ( ) ;
577
575
console . log ( `SDK response received ${ JSON . stringify ( response ) } ` ) ;
@@ -582,28 +580,87 @@ var AwsApiCallHandler = class extends CustomResourceHandler {
582
580
const flatData = {
583
581
...flatten ( respond )
584
582
} ;
585
- return request2 . flattenResponse === "true" ? flatData : respond ;
583
+ const resp = request2 . flattenResponse === "true" ? flatData : respond ;
584
+ console . log ( `Returning result ${ JSON . stringify ( resp ) } ` ) ;
585
+ return resp ;
586
586
}
587
587
} ;
588
+ function isJsonString ( value ) {
589
+ try {
590
+ return JSON . parse ( value ) ;
591
+ } catch {
592
+ return value ;
593
+ }
594
+ }
588
595
589
596
// lib/assertions/providers/lambda-handler/types.ts
590
597
var ASSERT_RESOURCE_TYPE = "Custom::DeployAssert@AssertEquals" ;
591
598
var SDK_RESOURCE_TYPE_PREFIX = "Custom::DeployAssert@SdkCall" ;
592
599
593
600
// lib/assertions/providers/lambda-handler/index.ts
594
601
async function handler ( event , context ) {
602
+ console . log ( `Event: ${ JSON . stringify ( { ...event , ResponseURL : "..." } ) } ` ) ;
595
603
const provider = createResourceHandler ( event , context ) ;
596
- await provider . handle ( ) ;
604
+ try {
605
+ if ( event . RequestType === "Delete" ) {
606
+ await provider . respond ( {
607
+ status : "SUCCESS" ,
608
+ reason : "OK"
609
+ } ) ;
610
+ return ;
611
+ }
612
+ const result = await provider . handle ( ) ;
613
+ const actualPath = event . ResourceProperties . actualPath ;
614
+ const actual = actualPath ? result [ `apiCallResponse.${ actualPath } ` ] : result . apiCallResponse ;
615
+ if ( "expected" in event . ResourceProperties ) {
616
+ const assertion = new AssertionHandler ( {
617
+ ...event ,
618
+ ResourceProperties : {
619
+ ServiceToken : event . ServiceToken ,
620
+ actual,
621
+ expected : event . ResourceProperties . expected
622
+ }
623
+ } , context ) ;
624
+ try {
625
+ const assertionResult = await assertion . handle ( ) ;
626
+ await provider . respond ( {
627
+ status : "SUCCESS" ,
628
+ reason : "OK" ,
629
+ data : {
630
+ ...assertionResult ,
631
+ ...result
632
+ }
633
+ } ) ;
634
+ return ;
635
+ } catch ( e ) {
636
+ await provider . respond ( {
637
+ status : "FAILED" ,
638
+ reason : e . message ?? "Internal Error"
639
+ } ) ;
640
+ return ;
641
+ }
642
+ }
643
+ await provider . respond ( {
644
+ status : "SUCCESS" ,
645
+ reason : "OK" ,
646
+ data : result
647
+ } ) ;
648
+ } catch ( e ) {
649
+ await provider . respond ( {
650
+ status : "FAILED" ,
651
+ reason : e . message ?? "Internal Error"
652
+ } ) ;
653
+ return ;
654
+ }
655
+ return ;
597
656
}
598
657
function createResourceHandler ( event , context ) {
599
658
if ( event . ResourceType . startsWith ( SDK_RESOURCE_TYPE_PREFIX ) ) {
600
659
return new AwsApiCallHandler ( event , context ) ;
601
- }
602
- switch ( event . ResourceType ) {
603
- case ASSERT_RESOURCE_TYPE :
604
- return new AssertionHandler ( event , context ) ;
605
- default :
606
- throw new Error ( `Unsupported resource type "${ event . ResourceType } ` ) ;
660
+ } else if ( event . ResourceType . startsWith ( ASSERT_RESOURCE_TYPE ) ) {
661
+ return new AssertionHandler ( event , context ) ;
662
+ } else {
663
+ throw new Error ( `Unsupported resource type "${ event . ResourceType } ` ) ;
607
664
}
608
665
}
609
666
// Annotate the CommonJS export names for ESM import in node:
0 commit comments