-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathapp.py
42 lines (34 loc) · 1.08 KB
/
app.py
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
39
40
41
42
from aws_cdk import (
aws_autoscaling as autoscaling,
aws_ec2 as ec2,
aws_ecs as ecs,
App, Stack
)
from constructs import Construct
class ECSCluster(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, *kwargs)
vpc = ec2.Vpc(
self, "MyVpc",
max_azs=2
)
asg = autoscaling.AutoScalingGroup(
self, "MyFleet",
instance_type=ec2.InstanceType("t2.xlarge"),
machine_image=ecs.EcsOptimizedImage.amazon_linux2(),
associate_public_ip_address=True,
desired_capacity=3,
vpc=vpc,
vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
)
cluster = ecs.Cluster(
self, 'EcsCluster',
vpc=vpc
)
capacity_provider = ecs.AsgCapacityProvider(self, "AsgCapacityProvider",
auto_scaling_group=asg
)
cluster.add_asg_capacity_provider(capacity_provider)
app = App()
ECSCluster(app, "MyFirstEcsCluster")
app.synth()