-
Notifications
You must be signed in to change notification settings - Fork 32
/
sample-vpc-cloud9-stack.ts
38 lines (29 loc) · 1.43 KB
/
sample-vpc-cloud9-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cloud9 from 'aws-cdk-lib/aws-cloud9';
import * as base from '../../lib/template/stack/vpc/vpc-base-stack';
import { Override } from '../../lib/template/stack/base/base-stack';
import { AppContext } from '../../lib/template/app-context';
import { StackConfig } from '../../lib/template/app-config'
export class SampleVpcCloud9Stack extends base.VpcBaseStack {
constructor(appContext: AppContext, stackConfig: StackConfig) {
super(appContext, stackConfig);
}
@Override
onLookupLegacyVpc(): base.VpcLegacyLookupProps | undefined {
return {
vpcNameLegacy: this.getVariable('VpcName')
};
}
@Override
onPostConstructor(baseVpc?: ec2.IVpc) {
const subnet = baseVpc?.publicSubnets[0];
new cloud9.CfnEnvironmentEC2(this, 'Cloud9Env2', {
name: this.withProjectPrefix('DatabaseConnection'),
instanceType: new ec2.InstanceType(this.stackConfig.InstanceType).toString(),
subnetId: subnet?.subnetId,
ownerArn: `arn:aws:iam::${this.commonProps.env?.account}:user/${this.stackConfig.IamUser}`
});
const databaseSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(this, 'DatabaseSecurityGroup', this.getParameter('DatabaseSecurityGroup'));
databaseSecurityGroup.addIngressRule(ec2.Peer.ipv4(subnet?.ipv4CidrBlock!), ec2.Port.tcp(3306), 'from cloud9 subnet');
}
}