@@ -10,8 +10,10 @@ import {
1010import {
1111 CfnSubnet ,
1212 FlowLogDestination ,
13+ InterfaceVpcEndpoint ,
1314 InterfaceVpcEndpointAwsService ,
1415 IpAddresses ,
16+ Peer ,
1517 Vpc
1618} from "aws-cdk-lib/aws-ec2"
1719import { Role , ServicePrincipal } from "aws-cdk-lib/aws-iam"
@@ -29,6 +31,7 @@ export interface VpcResourcesStackProps extends StackProps{
2931 */
3032
3133export class VpcResourcesStack extends Stack {
34+ readonly vpc : Vpc
3235 public constructor ( scope : App , id : string , props : VpcResourcesStackProps ) {
3336 super ( scope , id , props )
3437
@@ -89,13 +92,13 @@ export class VpcResourcesStack extends Stack {
8992 }
9093
9194 // add vpc private endpoints
92- vpc . addInterfaceEndpoint ( "ECRDockerEndpoint" , { service : InterfaceVpcEndpointAwsService . ECR_DOCKER } )
93- vpc . addInterfaceEndpoint ( "ECREndpoint" , { service : InterfaceVpcEndpointAwsService . ECR } )
94- vpc . addInterfaceEndpoint ( "SecretManagerEndpoint" , { service : InterfaceVpcEndpointAwsService . SECRETS_MANAGER } )
95- vpc . addInterfaceEndpoint ( "CloudWatchEndpoint" , { service : InterfaceVpcEndpointAwsService . CLOUDWATCH } )
96- vpc . addInterfaceEndpoint ( "CloudWatchLogsEndpoint" , { service : InterfaceVpcEndpointAwsService . CLOUDWATCH_LOGS } )
97- vpc . addInterfaceEndpoint ( "CloudWatchEventsEndpoint" , { service : InterfaceVpcEndpointAwsService . EVENTBRIDGE } )
98- vpc . addInterfaceEndpoint ( "SSMEndpoint" , { service : InterfaceVpcEndpointAwsService . SSM } )
95+ this . addInterfaceEndpoint ( "ECRDockerEndpoint" , InterfaceVpcEndpointAwsService . ECR_DOCKER )
96+ this . addInterfaceEndpoint ( "ECREndpoint" , InterfaceVpcEndpointAwsService . ECR )
97+ this . addInterfaceEndpoint ( "SecretManagerEndpoint" , InterfaceVpcEndpointAwsService . SECRETS_MANAGER )
98+ this . addInterfaceEndpoint ( "CloudWatchEndpoint" , InterfaceVpcEndpointAwsService . CLOUDWATCH )
99+ this . addInterfaceEndpoint ( "CloudWatchLogsEndpoint" , InterfaceVpcEndpointAwsService . CLOUDWATCH_LOGS )
100+ this . addInterfaceEndpoint ( "CloudWatchEventsEndpoint" , InterfaceVpcEndpointAwsService . CLOUDWATCH_EVENTS )
101+ this . addInterfaceEndpoint ( "SSMEndpoint" , InterfaceVpcEndpointAwsService . SSM )
99102
100103 //Outputs
101104
@@ -136,4 +139,12 @@ export class VpcResourcesStack extends Stack {
136139 } )
137140
138141 }
142+
143+ private addInterfaceEndpoint ( name : string , awsService : InterfaceVpcEndpointAwsService ) : void {
144+ const endpoint : InterfaceVpcEndpoint = this . vpc . addInterfaceEndpoint ( `${ name } ` , {
145+ service : awsService
146+ } )
147+
148+ endpoint . connections . allowFrom ( Peer . ipv4 ( this . vpc . vpcCidrBlock ) , endpoint . connections . defaultPort ! )
149+ }
139150}
0 commit comments