-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
90 lines (76 loc) · 2.62 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
from aws_cdk import core, aws_ecs, aws_ecr, aws_iam, aws_ec2
class CircuitBreakerDemo(core.Stack):
def __init__ (self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id , **kwargs)
# The code that defines your stack goes here
ecs_cluster = aws_ecs.Cluster(
self, "DemoCluster",
cluster_name="CB-Demo"
)
# ECR Image Repo
ecr_repo = aws_ecr.Repository(self, "ECRRepo", repository_name="flask-cb-demo")
# IAM Policy
iam_policy = aws_iam.PolicyDocument(
statements = [
aws_iam.PolicyStatement(
actions = [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
],
resources = [ ecr_repo.repository_arn ]
),
aws_iam.PolicyStatement(
actions = [
"ecr:GetAuthorizationToken"
],
resources = [ "*" ]
),
]
)
# IAM Task Role
task_execution_role = aws_iam.Role(
self, "TaskExecutionRole",
role_name="CircuitBreakerDemoRole",
assumed_by=aws_iam.ServicePrincipal(service="ecs-tasks.amazonaws.com"),
inline_policies = [
iam_policy
]
)
security_group = aws_ec2.SecurityGroup(
self, "WebSecGrp",
vpc=ecs_cluster.vpc
)
security_group.connections.allow_from_any_ipv4(
port_range=aws_ec2.Port(
protocol=aws_ec2.Protocol.TCP,
string_representation="Web Inbound",
from_port=5000,
to_port=5000
),
description="Web ingress"
)
core.CfnOutput(
self, "IAMRoleArn",
value=task_execution_role.role_arn,
export_name="IAMRoleArn"
)
core.CfnOutput(
self, "PublicSubnets",
value=",".join([x.subnet_id for x in ecs_cluster.vpc.public_subnets]),
export_name="PublicSubnets"
)
core.CfnOutput(
self, "SecurityGroupId",
value=security_group.security_group_id,
export_name="SecurityGroupId"
)
core.CfnOutput(
self, "EcrRepoUri",
value=ecr_repo.repository_uri,
export_name="EcrRepoUri"
)
app = core.App()
CircuitBreakerDemo(app, "circuit-breaker-demo")
app.synth()