Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VPCEndpoints on created VPC #1150

Merged
merged 11 commits into from
Nov 20, 2024
44 changes: 41 additions & 3 deletions deployment/migration-assistant-solution/lib/solutions-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import {Construct} from 'constructs';
import {
BlockDeviceVolume,
CloudFormationInit,
GatewayVpcEndpoint,
GatewayVpcEndpointAwsService,
IVpc,
InitCommand,
InitElement,
InitFile,
Instance,
InstanceClass,
InstanceSize,
InstanceType,
InterfaceVpcEndpoint,
InterfaceVpcEndpointAwsService,
IpProtocol,
MachineImage,
Vpc
} from "aws-cdk-lib/aws-ec2";
Expand Down Expand Up @@ -79,7 +85,7 @@ function addParameterLabel(labels: Record<string, ParameterLabel>, parameter: Cf
labels[parameter.logicalId] = {"default": labelName}
}

function importVPC(stack: Stack, vpdIdParameter: CfnParameter, availabilityZonesParameter: CfnParameter, privateSubnetIdsParameter: CfnParameter) {
function importVPC(stack: Stack, vpdIdParameter: CfnParameter, availabilityZonesParameter: CfnParameter, privateSubnetIdsParameter: CfnParameter): IVpc {
const availabilityZones = availabilityZonesParameter.valueAsList
const privateSubnetIds = privateSubnetIdsParameter.valueAsList
return Vpc.fromVpcAttributes(stack, 'ImportedVPC', {
Expand All @@ -95,6 +101,14 @@ function generateExportString(exports: Record<string, string>): string {
.join("; ");
}

function getVpcEndpointForEFS(stack: Stack): InterfaceVpcEndpointAwsService {
const isGovRegion = stack.region?.startsWith('us-gov-')
if (isGovRegion) {
return InterfaceVpcEndpointAwsService.ELASTIC_FILESYSTEM_FIPS;
}
return InterfaceVpcEndpointAwsService.ELASTIC_FILESYSTEM;
}

export class SolutionsInfrastructureStack extends Stack {

constructor(scope: Construct, id: string, props: SolutionsInfrastructureStackProps) {
Expand Down Expand Up @@ -162,9 +176,33 @@ export class SolutionsInfrastructureStack extends Stack {
role: bootstrapRole
})

let vpc;
let vpc: IVpc;
if (props.createVPC) {
vpc = new Vpc(this, 'Vpc', {});
vpc = new Vpc(this, 'Vpc', {
ipProtocol: IpProtocol.DUAL_STACK
});
// S3 used for storage and retrieval of snapshot data for backfills
new GatewayVpcEndpoint(this, 'S3VpcEndpoint', {
service: GatewayVpcEndpointAwsService.S3,
vpc: vpc,
});

const serviceEndpoints = [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only added endpoints with substantive amount of traffic. We had many more in the MA network-stack, but these are really the only ones that would see a price difference. Its a 1/3 the cost to use the VPCe compared to the NAT Gateway.

// Logs and disk usage scales based on total data transfer
InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS,
getVpcEndpointForEFS(this),

// Elastic container registry is used for all images in the solution
InterfaceVpcEndpointAwsService.ECR,
InterfaceVpcEndpointAwsService.ECR_DOCKER,
];

serviceEndpoints.forEach(service => {
new InterfaceVpcEndpoint(this, `${service.shortName}VpcEndpoint`, {
service,
vpc: vpc,
});
})
}
else {
const vpcIdParameter = new CfnParameter(this, 'VPCId', {
Expand Down
Loading