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

fix: updating ts loadbalancer to use VPC settings #160

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ rules:
import/order: off
simple-import-sort/imports: error
require-await: off
"@typescript-eslint/no-unused-expressions":
- error
- allowShortCircuit: true
- allowTernary: true
"@typescript-eslint/no-unsafe-assignment": warn
"@typescript-eslint/interface-name-prefix": off
"@typescript-eslint/no-empty-interface": off
Expand Down
12 changes: 10 additions & 2 deletions lib/osml/osml_vpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
* Copyright 2023-2025 Amazon.com, Inc. or its affiliates.
*/

import { RemovalPolicy } from "aws-cdk-lib";
Expand Down Expand Up @@ -51,6 +51,11 @@ export class OSMLVpcConfig extends BaseConfig {
*/
public IAM_FLOW_LOG_ROLE_NAME?: string;

/**
* Specify whether to disable creating VPC endpoints on the VPC.
*/
public ENABLE_VPC_ENDPOINTS?: boolean;

/**
* Constructor for MRDataplaneConfig.
* @param config - The configuration object for the VPC.
Expand All @@ -60,6 +65,7 @@ export class OSMLVpcConfig extends BaseConfig {
super({
// Set default values here
VPC_NAME: "OSML-VPC",
ENABLE_VPC_ENDPOINTS: true,
...config
});
}
Expand Down Expand Up @@ -174,7 +180,9 @@ export class OSMLVpc extends Construct {
this.vpc = vpc;
this.vpcDefaultSecurityGroup = vpc.vpcDefaultSecurityGroup;

this.setupVpcEndpoints(props);
if (this.config.ENABLE_VPC_ENDPOINTS) {
this.setupVpcEndpoints(props);
}
}

this.selectSubnets();
Expand Down
42 changes: 27 additions & 15 deletions lib/osml/tile_server/ts_dataplane.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Amazon.com, Inc. or its affiliates.
* Copyright 2023-2025 Amazon.com, Inc. or its affiliates.
*/

import { Duration, RemovalPolicy } from "aws-cdk-lib";
Expand All @@ -22,6 +22,7 @@ import {
Cluster,
Compatibility,
ContainerDefinition,
ContainerInsights,
Protocol as ecs_protocol,
TaskDefinition
} from "aws-cdk-lib/aws-ecs";
Expand All @@ -34,10 +35,11 @@ import {
ThroughputMode
} from "aws-cdk-lib/aws-efs";
import {
ApplicationLoadBalancer,
NetworkLoadBalancer,
Protocol as elbv2_protocol
} from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { AlbTarget } from "aws-cdk-lib/aws-elasticloadbalancingv2-targets";
import { IpTarget } from "aws-cdk-lib/aws-elasticloadbalancingv2-targets";
import {
AnyPrincipal,
IRole,
Expand Down Expand Up @@ -179,12 +181,6 @@ export class TSDataplaneConfig extends BaseConfig {
*/
public ECS_EXECUTION_ROLE_NAME?: string | undefined;

/**
* The namespace for metrics.
* @default "OSML"
*/
public ECS_METRICS_NAMESPACE: string;

/**
* The port to use in Network Load Balancer.
* @default 80
Expand Down Expand Up @@ -390,6 +386,11 @@ export class TSDataplane extends Construct {
*/
public containerDefinition: ContainerDefinition;

/**
* The application load balancer to be used for the FargateService.
*/
public alb: ApplicationLoadBalancer;

/**
* The Fargate service for the TSDataplane container.
*/
Expand Down Expand Up @@ -542,7 +543,9 @@ export class TSDataplane extends Construct {
this.cluster = new Cluster(this, "TSCluster", {
clusterName: this.config.ECS_CLUSTER_NAME,
vpc: props.osmlVpc.vpc,
containerInsights: props.account.prodLike
containerInsightsV2: props.account.prodLike
? ContainerInsights.ENABLED
: ContainerInsights.DISABLED
});

// Define our ECS task
Expand Down Expand Up @@ -608,6 +611,16 @@ export class TSDataplane extends Construct {
protocol: ecs_protocol.TCP
});

// Create the ALB
this.alb = new ApplicationLoadBalancer(
this,
"TSServiceApplicationLoadBalancer",
{
vpc: props.osmlVpc.vpc,
vpcSubnets: props.osmlVpc.selectedSubnets
}
);

// Set up Fargate service
this.fargateService = new ApplicationLoadBalancedFargateService(
this,
Expand All @@ -619,10 +632,12 @@ export class TSDataplane extends Construct {
securityGroups: this.securityGroup ? [this.securityGroup] : [],
taskSubnets: props.osmlVpc.selectedSubnets,
assignPublicIp: false,
publicLoadBalancer: false
publicLoadBalancer: false,
loadBalancer: this.alb
}
);
this.fargateService.node.addDependency(this.tsContainer);
this.fargateService.node.addDependency(this.alb);

// Allow access to EFS from Fargate ECS
this.fileSystem.grantRootAccess(
Expand Down Expand Up @@ -693,12 +708,9 @@ export class TSDataplane extends Construct {

nlbListener.addTargets("TSNlbTargetGroup", {
targets: [
new AlbTarget(
this.fargateService.loadBalancer,
this.config.ECS_NETWORK_LOAD_BALANCER_PORT
)
new IpTarget(this.fargateService.loadBalancer.loadBalancerDnsName)
],
port: this.config.ECS_NETWORK_LOAD_BALANCER_PORT
port: this.config.ECS_NETWORK_LOAD_BALANCER_PORT // Target port
});

const vpcLink = new VpcLink(this, "TSVpcLink", {
Expand Down
Loading
Loading