@@ -14,13 +14,11 @@ import {
14
14
import { Unit } from 'aws-cdk-lib/aws-cloudwatch' ;
15
15
import {
16
16
AmazonLinuxCpuType ,
17
- AmazonLinuxGeneration ,
18
17
CloudFormationInit ,
19
18
ISecurityGroup ,
20
19
IVpc ,
21
20
InitCommand ,
22
21
InitElement ,
23
- InitPackage ,
24
22
Instance ,
25
23
InstanceClass ,
26
24
InstanceSize ,
@@ -40,6 +38,7 @@ import {
40
38
BaseNetworkListenerProps ,
41
39
ListenerCertificate ,
42
40
NetworkListener , NetworkLoadBalancer , Protocol ,
41
+ SslPolicy ,
43
42
} from 'aws-cdk-lib/aws-elasticloadbalancingv2' ;
44
43
import { InstanceTarget } from 'aws-cdk-lib/aws-elasticloadbalancingv2-targets' ;
45
44
import {
@@ -59,9 +58,9 @@ import {
59
58
} from '../opensearch-config/node-config' ;
60
59
import { RemoteStoreResources } from './remote-store-resources' ;
61
60
62
- enum cpuArchEnum {
63
- X64 = 'x64' ,
64
- ARM64 = 'arm64'
61
+ enum cpuArchEnum {
62
+ X64 = 'x64' ,
63
+ ARM64 = 'arm64'
65
64
}
66
65
67
66
export enum LoadBalancerType {
@@ -142,11 +141,11 @@ export interface InfraProps extends StackProps {
142
141
/** Whether to enable monioring with alarms */
143
142
readonly enableMonitoring ?: boolean ,
144
143
/** Certificate ARN to attach to the listener */
145
- readonly certificateArn ?: string
144
+ readonly certificateArn ?: string
146
145
/** Map opensearch port on load balancer to */
147
- readonly mapOpensearchPortTo ?: number
146
+ readonly mapOpensearchPortTo ?: number
148
147
/** Map opensearch-dashboards port on load balancer to */
149
- readonly mapOpensearchDashboardsPortTo ?: number
148
+ readonly mapOpensearchDashboardsPortTo ?: number
150
149
/** Type of load balancer to use (e.g., 'nlb' or 'alb') */
151
150
readonly loadBalancerType ?: LoadBalancerType
152
151
/** Use instance based storage (if supported) on ec2 instance */
@@ -470,7 +469,7 @@ export class InfraStack extends Stack {
470
469
471
470
if ( this . opensearchPortMapping === this . opensearchDashboardsPortMapping ) {
472
471
throw new Error ( 'OpenSearch and OpenSearch-Dashboards cannot be mapped to the same port! Please provide different port numbers.'
473
- + ` Current mapping is OpenSearch:${ this . opensearchPortMapping } OpenSearch-Dashboards:${ this . opensearchDashboardsPortMapping } ` ) ;
472
+ + ` Current mapping is OpenSearch:${ this . opensearchPortMapping } OpenSearch-Dashboards:${ this . opensearchDashboardsPortMapping } ` ) ;
474
473
}
475
474
476
475
const useSSLOpensearchListener = ! this . securityDisabled && ! this . minDistribution && this . opensearchPortMapping === 443 && certificateArn !== 'undefined' ;
@@ -485,7 +484,7 @@ export class InfraStack extends Stack {
485
484
let dashboardsListener : NetworkListener | ApplicationListener ;
486
485
if ( this . dashboardsUrl !== 'undefined' ) {
487
486
const useSSLDashboardsListener = ! this . securityDisabled && ! this . minDistribution
488
- && this . opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined' ;
487
+ && this . opensearchDashboardsPortMapping === 443 && certificateArn !== 'undefined' ;
489
488
dashboardsListener = InfraStack . createListener (
490
489
this . elb ,
491
490
this . elbType ,
@@ -537,12 +536,12 @@ export class InfraStack extends Stack {
537
536
538
537
if ( this . dashboardsUrl !== 'undefined' ) {
539
538
InfraStack . addTargetsToListener (
540
- dashboardsListener ! ,
541
- this . elbType ,
542
- 'single-node-osd-target' ,
543
- 5601 ,
544
- new InstanceTarget ( singleNodeInstance ) ,
545
- false ,
539
+ dashboardsListener ! ,
540
+ this . elbType ,
541
+ 'single-node-osd-target' ,
542
+ 5601 ,
543
+ new InstanceTarget ( singleNodeInstance ) ,
544
+ false ,
546
545
) ;
547
546
}
548
547
new CfnOutput ( this , 'private-ip' , {
@@ -761,12 +760,12 @@ export class InfraStack extends Stack {
761
760
762
761
if ( this . dashboardsUrl !== 'undefined' ) {
763
762
InfraStack . addTargetsToListener (
764
- dashboardsListener ! ,
765
- this . elbType ,
766
- 'dashboardsTarget' ,
767
- 5601 ,
768
- clientNodeAsg ,
769
- false ,
763
+ dashboardsListener ! ,
764
+ this . elbType ,
765
+ 'dashboardsTarget' ,
766
+ 5601 ,
767
+ clientNodeAsg ,
768
+ false ,
770
769
) ;
771
770
}
772
771
}
@@ -804,7 +803,7 @@ export class InfraStack extends Stack {
804
803
805
804
if ( ( nodeType === 'data' || nodeType === 'single-node' ) && this . useInstanceBasedStorage ) {
806
805
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex; sudo mkfs -t xfs /dev/nvme1n1; '
807
- + 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data' ,
806
+ + 'sudo mkdir /mnt/data; sudo mount /dev/nvme1n1 /mnt/data; sudo chown -R ec2-user:ec2-user /mnt/data' ,
808
807
{
809
808
ignoreErrors : false ,
810
809
} ) ) ;
@@ -813,11 +812,11 @@ export class InfraStack extends Stack {
813
812
814
813
const cwInit = [
815
814
InitCommand . shellCommand ( 'MAX_RETRIES=5; RETRY_DELAY=10; for i in $(seq 1 $MAX_RETRIES); '
816
- + 'do sudo yum install -y amazon-cloudwatch-agent && break || '
817
- + '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done' ) ,
815
+ + 'do sudo yum install -y amazon-cloudwatch-agent && break || '
816
+ + '{ echo "Attempt $i/$MAX_RETRIES failed. Retrying in $RETRY_DELAY seconds..."; sleep $RETRY_DELAY; }; done' ) ,
818
817
InitCommand . shellCommand ( 'arc=$(arch); if [ "$arc" == "aarch64" ]; then dist="arm64"; else dist="amd64"; fi; '
819
- + 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
820
- + '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq' ) ,
818
+ + 'sudo wget -nv https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_$dist '
819
+ + '-O /usr/bin/yq && sudo chmod 755 /usr/bin/yq' ) ,
821
820
CloudwatchAgent . asInitFile ( '/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json' ,
822
821
{
823
822
agent : {
@@ -900,7 +899,7 @@ export class InfraStack extends Stack {
900
899
InitCommand . shellCommand ( 'set -ex;/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s' ) ,
901
900
InitCommand . shellCommand ( 'set -ex; sudo echo "vm.max_map_count=262144" >> /etc/sysctl.conf;sudo sysctl -p' ) ,
902
901
InitCommand . shellCommand ( `set -ex;mkdir opensearch; curl -L ${ this . distributionUrl } -o opensearch.tar.gz;`
903
- + 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;' , {
902
+ + 'tar zxf opensearch.tar.gz -C opensearch --strip-components=1; chown -R ec2-user:ec2-user opensearch;' , {
904
903
cwd : currentWorkDir ,
905
904
ignoreErrors : false ,
906
905
} ) ,
@@ -950,8 +949,8 @@ export class InfraStack extends Stack {
950
949
} ) ) ;
951
950
} else {
952
951
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
953
- + `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${ this . distVersion } /latest/linux/${ this . cpuArch } `
954
- + `/tar/builds/opensearch/core-plugins/discovery-ec2-${ this . distVersion } .zip --batch` , {
952
+ + `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${ this . distVersion } /latest/linux/${ this . cpuArch } `
953
+ + `/tar/builds/opensearch/core-plugins/discovery-ec2-${ this . distVersion } .zip --batch` , {
955
954
cwd : currentWorkDir ,
956
955
ignoreErrors : false ,
957
956
} ) ) ;
@@ -997,8 +996,8 @@ export class InfraStack extends Stack {
997
996
} ) ) ;
998
997
} else {
999
998
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex;cd opensearch;sudo -u ec2-user bin/opensearch-plugin install '
1000
- + `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${ this . distVersion } /latest/linux/${ this . cpuArch } `
1001
- + `/tar/builds/opensearch/core-plugins/repository-s3-${ this . distVersion } .zip --batch` , {
999
+ + `https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${ this . distVersion } /latest/linux/${ this . cpuArch } `
1000
+ + `/tar/builds/opensearch/core-plugins/repository-s3-${ this . distVersion } .zip --batch` , {
1002
1001
cwd : currentWorkDir ,
1003
1002
ignoreErrors : false ,
1004
1003
} ) ) ;
@@ -1017,7 +1016,7 @@ export class InfraStack extends Stack {
1017
1016
// Check if there are any jvm properties being passed
1018
1017
if ( this . jvmSysProps . toString ( ) !== 'undefined' ) {
1019
1018
cfnInitConfig . push ( InitCommand . shellCommand ( `set -ex; cd opensearch; jvmSysPropsList=$(echo "${ this . jvmSysProps . toString ( ) } " | tr ',' '\\n');`
1020
- + 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done' ,
1019
+ + 'for sysProp in $jvmSysPropsList;do echo "-D$sysProp" >> config/jvm.options;done' ,
1021
1020
{
1022
1021
cwd : currentWorkDir ,
1023
1022
ignoreErrors : false ,
@@ -1039,7 +1038,7 @@ export class InfraStack extends Stack {
1039
1038
1040
1039
if ( this . additionalConfig . toString ( ) !== 'undefined' ) {
1041
1040
cfnInitConfig . push ( InitCommand . shellCommand ( `set -ex; cd opensearch/config; echo "${ this . additionalConfig } ">additionalConfig.yml; `
1042
- + 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P' ,
1041
+ + 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch.yml additionalConfig.yml -P' ,
1043
1042
{
1044
1043
cwd : currentWorkDir ,
1045
1044
ignoreErrors : false ,
@@ -1072,7 +1071,7 @@ export class InfraStack extends Stack {
1072
1071
} ) ) ;
1073
1072
} else {
1074
1073
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex;cd opensearch; '
1075
- + `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${ this . adminPassword } ./opensearch-tar-install.sh >> install.log 2>&1 &` ,
1074
+ + `sudo -u ec2-user nohup env OPENSEARCH_INITIAL_ADMIN_PASSWORD=${ this . adminPassword } ./opensearch-tar-install.sh >> install.log 2>&1 &` ,
1076
1075
{
1077
1076
cwd : currentWorkDir ,
1078
1077
ignoreErrors : false ,
@@ -1082,7 +1081,7 @@ export class InfraStack extends Stack {
1082
1081
// If OpenSearch-Dashboards URL is present
1083
1082
if ( this . dashboardsUrl !== 'undefined' ) {
1084
1083
cfnInitConfig . push ( InitCommand . shellCommand ( `set -ex;mkdir opensearch-dashboards; curl -L ${ this . dashboardsUrl } -o opensearch-dashboards.tar.gz;`
1085
- + 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;' , {
1084
+ + 'tar zxf opensearch-dashboards.tar.gz -C opensearch-dashboards --strip-components=1; chown -R ec2-user:ec2-user opensearch-dashboards;' , {
1086
1085
cwd : currentWorkDir ,
1087
1086
ignoreErrors : false ,
1088
1087
} ) ) ;
@@ -1095,9 +1094,9 @@ export class InfraStack extends Stack {
1095
1094
1096
1095
if ( this . securityDisabled && ! this . minDistribution ) {
1097
1096
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex;cd opensearch-dashboards;'
1098
- + './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
1099
- + 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
1100
- + 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml' ,
1097
+ + './bin/opensearch-dashboards-plugin remove securityDashboards --allow-root;'
1098
+ + 'sed -i /^opensearch_security/d config/opensearch_dashboards.yml;'
1099
+ + 'sed -i \'s/https/http/\' config/opensearch_dashboards.yml' ,
1101
1100
{
1102
1101
cwd : currentWorkDir ,
1103
1102
ignoreErrors : false ,
@@ -1106,7 +1105,7 @@ export class InfraStack extends Stack {
1106
1105
1107
1106
if ( this . additionalOsdConfig . toString ( ) !== 'undefined' ) {
1108
1107
cfnInitConfig . push ( InitCommand . shellCommand ( `set -ex;cd opensearch-dashboards/config; echo "${ this . additionalOsdConfig } ">additionalOsdConfig.yml; `
1109
- + 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P' ,
1108
+ + 'yq eval-all -i \'. as $item ireduce ({}; . * $item)\' opensearch_dashboards.yml additionalOsdConfig.yml -P' ,
1110
1109
{
1111
1110
cwd : currentWorkDir ,
1112
1111
ignoreErrors : false ,
@@ -1115,7 +1114,7 @@ export class InfraStack extends Stack {
1115
1114
1116
1115
// Starting OpenSearch-Dashboards
1117
1116
cfnInitConfig . push ( InitCommand . shellCommand ( 'set -ex;cd opensearch-dashboards;'
1118
- + 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &' , {
1117
+ + 'sudo -u ec2-user nohup ./bin/opensearch-dashboards > dashboard_install.log 2>&1 &' , {
1119
1118
cwd : currentWorkDir ,
1120
1119
ignoreErrors : false ,
1121
1120
} ) ) ;
@@ -1146,6 +1145,7 @@ export class InfraStack extends Stack {
1146
1145
}
1147
1146
1148
1147
const listenerProps : BaseApplicationListenerProps | BaseNetworkListenerProps = {
1148
+ sslPolicy : SslPolicy . RECOMMENDED_TLS ,
1149
1149
port,
1150
1150
protocol,
1151
1151
certificates : useSSL ? [ ListenerCertificate . fromArn ( certificateArn ) ] : undefined ,
0 commit comments