-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.ts
37 lines (27 loc) · 1.03 KB
/
index.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
import autoscaling = require('@aws-cdk/aws-autoscaling');
import ec2 = require('@aws-cdk/aws-ec2');
import { InstanceType } from '@aws-cdk/aws-ec2';
import ecs = require('@aws-cdk/aws-ecs');
import cdk = require('@aws-cdk/cdk');
class ECSCluster extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = new ec2.VpcNetwork(this, 'MyVpc', { maxAZs: 2 });
const asg = new autoscaling.AutoScalingGroup(this, 'MyFleet', {
instanceType: new InstanceType("t2.xlarge"),
machineImage: new ecs.EcsOptimizedAmi(),
associatePublicIpAddress: true,
updateType: autoscaling.UpdateType.ReplacingUpdate,
desiredCapacity: 3,
vpc
});
const cluster = new ecs.Cluster(this, 'EcsCluster', { vpc });
cluster.addAutoScalingGroup(asg);
cluster.addCapacity('DefaultAutoScalingGroup', {
instanceType: new ec2.InstanceType('t2.micro')
});
}
}
const app = new cdk.App();
new ECSCluster(app, 'MyFirstEcsCluster');
app.run();