Skip to content

Commit

Permalink
Add option to create internal NLB
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Singh <sngri@amazon.com>
  • Loading branch information
rishabh6788 committed May 3, 2023
1 parent d3b12a8 commit 2629a7d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ In order to deploy both the stacks the user needs to provide a set of required a
| account (Optional) | string | User provided aws account |
| dataNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| mlNodeStorage (Optional) | string | User provided ebs block storage size, defaults to 100Gb |
| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` |
| use50PercentHeap (Optional) | boolean | Boolean flag to use 50% of physical memory as heap. Default is 1GB. e.g., `--context use50PercentHeap=true` |
| isInternal (Optional) | boolean | Boolean flag to make network load balancer internal. Default is internet-facing e.g., `--context isInternal=true` |



Expand Down
13 changes: 7 additions & 6 deletions lib/infra/infra-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface infraProps extends StackProps{
readonly jvmSysPropsString?: string,
readonly additionalConfig?: string,
readonly use50PercentHeap: boolean,
readonly isInternal: boolean,
}

export class InfraStack extends Stack {
Expand Down Expand Up @@ -86,26 +87,26 @@ export class InfraStack extends Stack {
const ec2InstanceType = (props.cpuType === AmazonLinuxCpuType.X86_64)
? InstanceType.of(InstanceClass.C5, InstanceSize.XLARGE) : InstanceType.of(InstanceClass.C6G, InstanceSize.XLARGE);

const alb = new NetworkLoadBalancer(this, 'publicNlb', {
const nlb = new NetworkLoadBalancer(this, 'clusterNlb', {
vpc: props.vpc,
internetFacing: true,
internetFacing: (!props.isInternal),
crossZoneEnabled: true,
});

if (!props.securityDisabled && !props.minDistribution) {
opensearchListener = alb.addListener('opensearch', {
opensearchListener = nlb.addListener('opensearch', {
port: 443,
protocol: Protocol.TCP,
});
} else {
opensearchListener = alb.addListener('opensearch', {
opensearchListener = nlb.addListener('opensearch', {
port: 80,
protocol: Protocol.TCP,
});
}

if (props.dashboardsUrl !== 'undefined') {
dashboardsListener = alb.addListener('dashboards', {
dashboardsListener = nlb.addListener('dashboards', {
port: 8443,
protocol: Protocol.TCP,
});
Expand Down Expand Up @@ -325,7 +326,7 @@ export class InfraStack extends Stack {
}

new CfnOutput(this, 'loadbalancer-url', {
value: alb.loadBalancerDnsName,
value: nlb.loadBalancerDnsName,
});
}

Expand Down
4 changes: 4 additions & 0 deletions lib/os-cluster-entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ export class OsClusterEntrypoint {
const use50heap = `${scope.node.tryGetContext('use50PercentHeap')}`;
const use50PercentHeap = use50heap === 'true';

const nlbScheme = `${scope.node.tryGetContext('isInternal')}`;
const isInternal = nlbScheme === 'true';

const network = new NetworkStack(scope, 'opensearch-network-stack', {
cidrBlock: cidrRange,
maxAzs: 3,
Expand Down Expand Up @@ -196,6 +199,7 @@ export class OsClusterEntrypoint {
jvmSysPropsString: jvmSysProps,
additionalConfig: ymlConfig,
use50PercentHeap,
isInternal,
...props,
});

Expand Down
7 changes: 7 additions & 0 deletions test/os-cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ test('Test Resources with security enabled multi-node with existing Vpc', () =>
},
],
});
infraTemplate.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Scheme: 'internet-facing',
});
});

test('Test Resources with security enabled single-node cluster', () => {
Expand All @@ -121,6 +124,7 @@ test('Test Resources with security enabled single-node cluster', () => {
serverAccessType: 'prefixList',
restrictServerAccessTo: 'pl-12345',
dataNodeStorage: 200,
isInternal: true,
},
});

Expand Down Expand Up @@ -153,4 +157,7 @@ test('Test Resources with security enabled single-node cluster', () => {
},
],
});
infraTemplate.hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
Scheme: 'internal',
});
});

0 comments on commit 2629a7d

Please sign in to comment.