| 8 | |
| 9 | # Need to Change different app |
| 10 | class FargateAppStack(Stack): |
| 11 | |
| 12 | def __init__(self, scope: Construct, id: str, **kwargs) -> None: |
| 13 | super().__init__(scope, id, **kwargs) |
| 14 | |
| 15 | # Create VPC and Fargate Cluster |
| 16 | # NOTE: Limit AZs to avoid reaching resource quotas |
| 17 | vpc = ec2.Vpc( |
| 18 | self, "MyVpc", |
| 19 | max_azs=2 |
| 20 | ) |
| 21 | |
| 22 | cluster = ecs.Cluster( |
| 23 | self, 'Ec2Cluster', |
| 24 | vpc=vpc |
| 25 | ) |
| 26 | |
| 27 | self.fargate_service = ecs_patterns.NetworkLoadBalancedFargateService( |
| 28 | self, "FargateService", |
| 29 | cluster=cluster, |
| 30 | task_image_options=ecs_patterns.NetworkLoadBalancedTaskImageOptions( |
| 31 | image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample") |
| 32 | ) |
| 33 | ) |
| 34 | |
| 35 | self.fargate_service.service.connections.security_groups[0].add_ingress_rule( |
| 36 | peer = ec2.Peer.ipv4(vpc.vpc_cidr_block), |
| 37 | connection = ec2.Port.tcp(80), |
| 38 | description="Allow http inbound from VPC" |
| 39 | ) |
| 40 | |
| 41 | CfnOutput( |
| 42 | self, "LoadBalancerDNS", |
| 43 | value=self.fargate_service.load_balancer.load_balancer_dns_name |
| 44 | ) |