@@ -75,6 +75,12 @@ export class LambdaDestination implements IEventDestination {
75
75
this . policyDocument = new iam . PolicyDocument ( {
76
76
statements : [ policy ] ,
77
77
} ) ;
78
+
79
+ if ( ! func . permissionsNode . tryFindChild ( 'AppConfigPermission' ) ) {
80
+ func . addPermission ( 'AppConfigPermission' , {
81
+ principal : new iam . ServicePrincipal ( 'appconfig.amazonaws.com' ) ,
82
+ } ) ;
83
+ }
78
84
}
79
85
}
80
86
@@ -500,21 +506,19 @@ export class Extension extends Resource implements IExtension {
500
506
this . parameters = props . parameters ;
501
507
502
508
const resource = new CfnExtension ( this , 'Resource' , {
503
- actions : this . actions . reduce ( ( acc : { [ key : string ] : { [ key : string ] : string } [ ] } , cur : Action ) => {
509
+ actions : this . actions . reduce ( ( acc : { [ key : string ] : { [ key : string ] : string } [ ] } , cur : Action , index : number ) => {
504
510
const extensionUri = cur . eventDestination . extensionUri ;
505
511
const sourceType = cur . eventDestination . type ;
506
512
this . executionRole = cur . executionRole ;
513
+ const name = cur . name ?? `${ this . name } -${ index } ` ;
507
514
cur . actionPoints . forEach ( ( actionPoint ) => {
508
515
acc [ actionPoint ] = [
509
516
{
510
- Name : cur . name || Names . uniqueResourceName ( this , {
511
- maxLength : 64 ,
512
- separator : '-' ,
513
- } ) ,
517
+ Name : name ,
514
518
Uri : extensionUri ,
515
519
...( sourceType === SourceType . EVENTS || cur . invokeWithoutExecutionRole
516
520
? { }
517
- : { RoleArn : this . executionRole ?. roleArn || this . getExecutionRole ( cur . eventDestination ) . roleArn } ) ,
521
+ : { RoleArn : this . executionRole ?. roleArn || this . getExecutionRole ( cur . eventDestination , name ) . roleArn } ) ,
518
522
...( cur . description ? { Description : cur . description } : { } ) ,
519
523
} ,
520
524
] ;
@@ -543,8 +547,10 @@ export class Extension extends Resource implements IExtension {
543
547
} ) ;
544
548
}
545
549
546
- private getExecutionRole ( eventDestination : IEventDestination ) : iam . IRole {
547
- this . executionRole = new iam . Role ( this , `Role${ getHash ( eventDestination . extensionUri ) } ` , {
550
+ private getExecutionRole ( eventDestination : IEventDestination , actionName : string ) : iam . IRole {
551
+ const versionNumber = this . latestVersionNumber ? this . latestVersionNumber + 1 : 1 ;
552
+ const combinedObjects = stringifyObjects ( this . name , versionNumber , actionName ) ;
553
+ this . executionRole = new iam . Role ( this , `Role${ getHash ( combinedObjects ) } ` , {
548
554
roleName : PhysicalName . GENERATE_IF_NEEDED ,
549
555
assumedBy : new iam . ServicePrincipal ( 'appconfig.amazonaws.com' ) ,
550
556
inlinePolicies : {
@@ -652,13 +658,13 @@ export class ExtensibleBase implements IExtensible {
652
658
}
653
659
654
660
public addExtension ( extension : IExtension ) {
655
- this . addExtensionAssociation ( extension , {
656
- parameters : extension . parameters ,
657
- } ) ;
661
+ this . addExtensionAssociation ( extension ) ;
658
662
}
659
663
660
664
private getExtensionForActionPoint ( eventDestination : IEventDestination , actionPoint : ActionPoint , options ?: ExtensionOptions ) {
661
- const extension = new Extension ( this . scope , `Extension${ this . getExtensionHash ( eventDestination , actionPoint , options ) } ` , {
665
+ const name = options ?. name || this . getExtensionDefaultName ( ) ;
666
+ const versionNumber = options ?. latestVersionNumber ? options ?. latestVersionNumber + 1 : 1 ;
667
+ const extension = new Extension ( this . scope , `Extension${ this . getExtensionHash ( name , versionNumber ) } ` , {
662
668
actions : [
663
669
new Action ( {
664
670
eventDestination,
@@ -667,20 +673,22 @@ export class ExtensibleBase implements IExtensible {
667
673
] ,
668
674
} ) ,
669
675
] ,
676
+ name,
670
677
...( options ?. description ? { description : options . description } : { } ) ,
671
678
...( options ?. latestVersionNumber ? { latestVersionNumber : options . latestVersionNumber } : { } ) ,
672
- ...( options ?. name ? { name : options . name } : { } ) ,
673
679
...( options ?. parameters ? { parameters : options . parameters } : { } ) ,
674
680
} ) ;
675
- this . addExtensionAssociation ( extension , options ) ;
681
+ this . addExtensionAssociation ( extension ) ;
676
682
}
677
683
678
- private addExtensionAssociation ( extension : IExtension , options ?: ExtensionOptions ) {
679
- new CfnExtensionAssociation ( this . scope , `AssociationResource${ this . getExtensionAssociationHash ( extension ) } ` , {
684
+ private addExtensionAssociation ( extension : IExtension ) {
685
+ const versionNumber = extension ?. latestVersionNumber ? extension ?. latestVersionNumber + 1 : 1 ;
686
+ const name = extension . name ?? this . getExtensionDefaultName ( ) ;
687
+ new CfnExtensionAssociation ( this . scope , `AssociationResource${ this . getExtensionAssociationHash ( name , versionNumber ) } ` , {
680
688
extensionIdentifier : extension . extensionId ,
681
689
resourceIdentifier : this . resourceArn ,
682
690
extensionVersionNumber : extension . extensionVersionNumber ,
683
- parameters : options ? .parameters ?. reduce ( ( acc : { [ key : string ] : string } , cur : Parameter ) => {
691
+ parameters : extension . parameters ?. reduce ( ( acc : { [ key : string ] : string } , cur : Parameter ) => {
684
692
if ( cur . value ) {
685
693
acc [ cur . name ] = cur . value ;
686
694
}
@@ -689,16 +697,23 @@ export class ExtensibleBase implements IExtensible {
689
697
} ) ;
690
698
}
691
699
692
- private getExtensionHash ( eventDestination : IEventDestination , actionPoint : ActionPoint , options ?: ExtensionOptions ) {
693
- const combinedString = stringifyObjects ( eventDestination , actionPoint , options ) ;
700
+ private getExtensionHash ( name : string , versionNumber : number ) {
701
+ const combinedString = stringifyObjects ( name , versionNumber ) ;
694
702
return getHash ( combinedString ) ;
695
703
}
696
704
697
- private getExtensionAssociationHash ( extension : IExtension ) {
698
- const resourceIdentifier = this . resourceName ? this . resourceName : this . resourceArn ;
699
- const combinedString = stringifyObjects ( resourceIdentifier , extension . name , extension . extensionVersionNumber ) ;
705
+ private getExtensionAssociationHash ( name : string , versionNumber : number ) {
706
+ const resourceIdentifier = this . resourceName ?? this . resourceArn ;
707
+ const combinedString = stringifyObjects ( resourceIdentifier , name , versionNumber ) ;
700
708
return getHash ( combinedString ) ;
701
709
}
710
+
711
+ private getExtensionDefaultName ( ) {
712
+ return Names . uniqueResourceName ( this . scope , {
713
+ maxLength : 54 ,
714
+ separator : '-' ,
715
+ } ) + '-Extension' ;
716
+ }
702
717
}
703
718
704
719
/**
0 commit comments