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
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export class MigrationAssistanceStack extends Stack {

const streamingSecurityGroup = new SecurityGroup(this, 'trafficStreamSourceSG', {
vpc: props.vpc,
allowAllOutbound: false
allowAllOutbound: false,
allowAllIpv6Outbound: false,
});
streamingSecurityGroup.addIngressRule(streamingSecurityGroup, Port.allTraffic())
createMigrationStringParameter(this, streamingSecurityGroup.securityGroupId, {
Expand All @@ -180,6 +181,7 @@ export class MigrationAssistanceStack extends Stack {
const sharedLogsSG = new SecurityGroup(this, 'sharedLogsSG', {
vpc: props.vpc,
allowAllOutbound: false,
allowAllIpv6Outbound: false,
peternied marked this conversation as resolved.
Show resolved Hide resolved
});
sharedLogsSG.addIngressRule(sharedLogsSG, Port.allTraffic());

Expand All @@ -205,6 +207,7 @@ export class MigrationAssistanceStack extends Stack {
vpc: props.vpc,
// Required for retrieving ECR image at service startup
allowAllOutbound: true,
allowAllIpv6Outbound: true,
})
serviceSecurityGroup.addIngressRule(serviceSecurityGroup, Port.allTraffic());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export class NetworkStack extends Stack {
const defaultSecurityGroup = new SecurityGroup(this, 'osClusterAccessSG', {
vpc: this.vpc,
allowAllOutbound: false,
allowAllIpv6Outbound: false,
});
defaultSecurityGroup.addIngressRule(defaultSecurityGroup, Port.allTraffic());

Expand Down
51 changes: 48 additions & 3 deletions deployment/migration-assistant-solution/lib/solutions-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import {Construct} from 'constructs';
import {
BlockDeviceVolume,
CloudFormationInit,
GatewayVpcEndpoint,
GatewayVpcEndpointAwsService,
IVpc,
InitCommand,
InitElement,
InitFile,
Instance,
InstanceClass,
InstanceSize,
InstanceType,
InterfaceVpcEndpoint,
InterfaceVpcEndpointAwsService,
IpProtocol,
MachineImage,
SecurityGroup,
Vpc
} from "aws-cdk-lib/aws-ec2";
import {InstanceProfile, ManagedPolicy, Role, ServicePrincipal} from "aws-cdk-lib/aws-iam";
Expand Down Expand Up @@ -79,7 +86,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 +102,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 +177,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 Expand Up @@ -201,6 +240,11 @@ export class SolutionsInfrastructureStack extends Stack {
}),
]

const securityGroup = new SecurityGroup(this, 'BootstrapSecurityGroup', {
vpc: vpc,
allowAllOutbound: true,
allowAllIpv6Outbound: true,
});
new Instance(this, 'BootstrapEC2Instance', {
vpc: vpc,
vpcSubnets: {
Expand All @@ -220,6 +264,7 @@ export class SolutionsInfrastructureStack extends Stack {
initOptions: {
printLog: true,
},
securityGroup
});

const dynamicEc2ImageParameter = this.node.findAll()
Expand Down
Loading