|
6 | 6 | cluster = aws.ecs.Cluster('cluster') |
7 | 7 |
|
8 | 8 | # Read back the default VPC and public subnets, which we will use. |
9 | | -default_vpc = aws.ec2.get_vpc(default='true') |
| 9 | +default_vpc = aws.ec2.get_vpc(default=True) |
10 | 10 | default_vpc_subnets = aws.ec2.get_subnet_ids(vpc_id=default_vpc.id) |
11 | 11 |
|
12 | 12 | # Create a SecurityGroup that permits HTTP ingress and unrestricted egress. |
13 | 13 | group = aws.ec2.SecurityGroup('web-secgrp', |
14 | 14 | vpc_id=default_vpc.id, |
15 | 15 | description='Enable HTTP access', |
16 | | - ingress=[{ |
17 | | - 'protocol': 'tcp', |
18 | | - 'from_port': 80, |
19 | | - 'to_port': 80, |
20 | | - 'cidr_blocks': ['0.0.0.0/0'], |
21 | | - }], |
22 | | - egress=[{ |
23 | | - 'protocol': '-1', |
24 | | - 'from_port': 0, |
25 | | - 'to_port': 0, |
26 | | - 'cidr_blocks': ['0.0.0.0/0'], |
27 | | - }] |
| 16 | + ingress=[aws.ec2.SecurityGroupIngressArgs( |
| 17 | + protocol='tcp', |
| 18 | + from_port=80, |
| 19 | + to_port=80, |
| 20 | + cidr_blocks=['0.0.0.0/0'], |
| 21 | + )], |
| 22 | + egress=[aws.ec2.SecurityGroupEgressArgs( |
| 23 | + protocol='-1', |
| 24 | + from_port=0, |
| 25 | + to_port=0, |
| 26 | + cidr_blocks=['0.0.0.0/0'], |
| 27 | + )], |
28 | 28 | ) |
29 | 29 |
|
30 | 30 | # Create a load balancer to listen for HTTP traffic on port 80. |
31 | 31 | alb = aws.lb.LoadBalancer('app-lb', |
32 | 32 | security_groups=[group.id], |
33 | | - subnets=default_vpc_subnets.ids |
| 33 | + subnets=default_vpc_subnets.ids, |
34 | 34 | ) |
35 | 35 |
|
36 | 36 | atg = aws.lb.TargetGroup('app-tg', |
37 | 37 | port=80, |
38 | 38 | protocol='HTTP', |
39 | 39 | target_type='ip', |
40 | | - vpc_id=default_vpc.id |
| 40 | + vpc_id=default_vpc.id, |
41 | 41 | ) |
42 | 42 |
|
43 | 43 | wl = aws.lb.Listener('web', |
44 | 44 | load_balancer_arn=alb.arn, |
45 | 45 | port=80, |
46 | | - default_actions=[{ |
47 | | - 'type': 'forward', |
48 | | - 'target_group_arn': atg.arn |
49 | | - }] |
| 46 | + default_actions=[aws.lb.ListenerDefaultActionArgs( |
| 47 | + type='forward', |
| 48 | + target_group_arn=atg.arn, |
| 49 | + )], |
50 | 50 | ) |
51 | 51 |
|
52 | 52 | # Create an IAM role that can be used by our service's task. |
|
61 | 61 | }, |
62 | 62 | 'Action': 'sts:AssumeRole', |
63 | 63 | }] |
64 | | - }) |
| 64 | + }), |
65 | 65 | ) |
66 | 66 |
|
67 | 67 | rpa = aws.iam.RolePolicyAttachment('task-exec-policy', |
68 | 68 | role=role.name, |
69 | | - policy_arn='arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy' |
| 69 | + policy_arn='arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy', |
70 | 70 | ) |
71 | 71 |
|
72 | 72 | # Spin up a load balanced service running our container image. |
|
93 | 93 | desired_count=3, |
94 | 94 | launch_type='FARGATE', |
95 | 95 | task_definition=task_definition.arn, |
96 | | - network_configuration={ |
97 | | - 'assign_public_ip': 'true', |
98 | | - 'subnets': default_vpc_subnets.ids, |
99 | | - 'security_groups': [group.id] |
100 | | - }, |
101 | | - load_balancers=[{ |
102 | | - 'target_group_arn': atg.arn, |
103 | | - 'container_name': 'my-app', |
104 | | - 'container_port': 80 |
105 | | - }], |
| 96 | + network_configuration=aws.ecs.ServiceNetworkConfigurationArgs( |
| 97 | + assign_public_ip=True, |
| 98 | + subnets=default_vpc_subnets.ids, |
| 99 | + security_groups=[group.id], |
| 100 | + ), |
| 101 | + load_balancers=[aws.ecs.ServiceLoadBalancerArgs( |
| 102 | + target_group_arn=atg.arn, |
| 103 | + container_name='my-app', |
| 104 | + container_port=80, |
| 105 | + )], |
106 | 106 | opts=ResourceOptions(depends_on=[wl]), |
107 | 107 | ) |
108 | 108 |
|
|
0 commit comments