Skip to content

Commit e3bcbeb

Browse files
author
Zhoutong Wang
committed
version 1 for cdk
1 parent cf0705d commit e3bcbeb

File tree

11 files changed

+374
-256
lines changed

11 files changed

+374
-256
lines changed

source/resources/bin/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env node
22
import * as cdk from 'aws-cdk-lib';
33
import { MainStack } from '../lib/main-stack';
4-
4+
// import {RDSStack} from '../lib/rds/rds-stack';
5+
// import {AOSStack} from '../lib/aos/aos-stack';
56
// for development, use account/region from cdk cli
67
const devEnv = {
78
account: process.env.CDK_DEFAULT_ACCOUNT,
89
region: process.env.CDK_DEFAULT_REGION,
910
};
1011

1112
const app = new cdk.App();
13+
// new AOSStack(app, 'AOSStack', { env: devEnv });
1214
new MainStack(app, 'GenBiMainStack', { env: devEnv });
13-
15+
// new RDSStack(app, 'RDSStack', { env: devEnv })
1416
app.synth();
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import * as cdk from 'aws-cdk-lib';
2+
import { Construct } from 'constructs';
3+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
4+
import * as opensearch from 'aws-cdk-lib/aws-opensearchservice';
5+
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
6+
7+
export class AOSStack extends cdk.Stack {
8+
_vpc;
9+
_securityGroup;
10+
public readonly endpoint: string;
11+
12+
constructor(scope: Construct, id: string, props: cdk.StackProps) {
13+
super(scope, id, props);
14+
15+
this._vpc = ec2.Vpc.fromLookup(this, "VPC", {
16+
isDefault: true,
17+
});
18+
// Lookup a VPC
19+
// this._vpc = props.vpc;
20+
21+
// Create a Security Group for OpenSearch
22+
this._securityGroup = new ec2.SecurityGroup(this, 'GenBIOpenSearchSG', {
23+
vpc: this._vpc,
24+
description: 'Allow access to OpenSearch',
25+
allowAllOutbound: true
26+
});
27+
const secretName = 'GenBIAOSSecret'; // Add the secret name here
28+
const templatedSecret = new secretsmanager.Secret(this, 'TemplatedSecret', {
29+
secretName: secretName,
30+
description: 'Templated secret used for OpenSearch master user password',
31+
generateSecretString: {
32+
excludePunctuation: false,
33+
includeSpace: false,
34+
generateStringKey: 'password',
35+
passwordLength: 12,
36+
requireEachIncludedType: true,
37+
secretStringTemplate: JSON.stringify({ username: 'master-user' })
38+
},
39+
removalPolicy: cdk.RemovalPolicy.DESTROY
40+
});
41+
42+
// Allow inbound HTTP and HTTPS traffic
43+
this._securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(80), 'Allow HTTP access');
44+
this._securityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443), 'Allow HTTPS access');
45+
46+
// Find subnets in different availability zones
47+
const subnets = this._vpc.selectSubnets({
48+
subnetType: ec2.SubnetType.PUBLIC,
49+
}).subnets;
50+
51+
// if (subnets.length < 3) {
52+
// throw new Error('The VPC must have at least two public subnets in different availability zones.');
53+
// }
54+
55+
// Create the OpenSearch domain
56+
const domain = new opensearch.Domain(this, 'GenBiOpenSearchDomain', {
57+
version: opensearch.EngineVersion.OPENSEARCH_2_9,
58+
vpc: this._vpc,
59+
securityGroups: [this._securityGroup],
60+
vpcSubnets: [
61+
{ subnets: [subnets[0]] },
62+
],
63+
// vpcSubnets: SubnetSelection(one_per_az=True, subnet_type=aws_ec2.SubnetType.PUBLIC),
64+
capacity: {
65+
dataNodes: 1,
66+
dataNodeInstanceType: 'm5.large.search',
67+
multiAzWithStandbyEnabled: false
68+
},
69+
ebs: {
70+
volumeType: ec2.EbsDeviceVolumeType.GP3,
71+
volumeSize: 20,
72+
},
73+
zoneAwareness: {
74+
enabled: false
75+
},
76+
nodeToNodeEncryption: true,
77+
encryptionAtRest: {
78+
enabled: true
79+
},
80+
enforceHttps: true,
81+
fineGrainedAccessControl: {
82+
masterUserName: 'master-user',
83+
masterUserPassword: cdk.SecretValue.secretsManager(templatedSecret.secretArn, {
84+
jsonField: 'password'
85+
}
86+
),
87+
},
88+
});
89+
this.endpoint = domain.domainEndpoint;
90+
91+
new cdk.CfnOutput(this, 'AOSDomainEndpoint', {
92+
value: this.endpoint,
93+
description: 'The endpoint of the OpenSearch domain'
94+
});
95+
}
96+
}
97+
98+
// const app = new cdk.App();
99+
// new AOSStack(app, 'AOSStack', {
100+
// env: {
101+
// account: process.env.CDK_DEFAULT_ACCOUNT,
102+
// region: process.env.CDK_DEFAULT_REGION
103+
// }
104+
// });

source/resources/lib/ec2/cn_user_data/install_docker.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

source/resources/lib/ec2/cn_user_data/setup_app.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

source/resources/lib/ec2/ec2-stack.ts

Lines changed: 0 additions & 101 deletions
This file was deleted.

source/resources/lib/ec2/user_data/install_docker.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

source/resources/lib/ec2/user_data/setup_app.sh

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)