forked from snyk/snyk-iac-aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbalancer-stack.ts
36 lines (30 loc) · 1005 Bytes
/
loadbalancer-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
#!/usr/bin/env node
import autoscaling = require('@aws-cdk/aws-autoscaling');
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import cdk = require('@aws-cdk/core');
export class LoadBalancerStack extends cdk.Stack {
constructor(app: cdk.App, id: string) {
super(app, id);
const vpc = new ec2.Vpc(this, 'VPC');
const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage(),
});
const lb = new elb.LoadBalancer(this, 'LB', {
vpc,
internetFacing: true,
healthCheck: {
port: 80
},
});
lb.addTarget(asg);
const listener = lb.addListener({ externalPort: 80 });
listener.connections.allowDefaultPortFromAnyIpv4('Open to the world');
}
}
//
// const app = new cdk.App();
// new LoadBalancerStack(app, 'LoadBalancerStack');
// app.synth();