AWSTemplateFormatVersion: '2010-09-09' Description: Creates an Application Load Balancer, which will front-end an ECS Service Parameters: VpcId: Type: String Subnets: Type: List Resources: SecurityGroup: Type: "AWS::EC2::SecurityGroup" Properties: GroupDescription: !Sub ${AWS::StackName}-alb SecurityGroupIngress: - CidrIp: "0.0.0.0/0" IpProtocol: "TCP" FromPort: 80 ToPort: 80 VpcId: !Ref VpcId LoadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Subnets: !Ref Subnets SecurityGroups: - !Ref SecurityGroup LoadBalancerListener: Type: AWS::ElasticLoadBalancingV2::Listener Properties: LoadBalancerArn: !Ref LoadBalancer Port: 80 Protocol: HTTP DefaultActions: - Type: forward TargetGroupArn: !Ref TargetGroup TargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup DependsOn: LoadBalancer Properties: # Name: name of LB VpcId: !Ref VpcId Port: 80 Protocol: HTTP Matcher: HttpCode: 200-299 HealthCheckIntervalSeconds: 10 HealthCheckPath: / HealthCheckProtocol: HTTP HealthCheckTimeoutSeconds: 5 HealthyThresholdCount: 2 TargetGroupAttributes: - Key: deregistration_delay.timeout_seconds Value: 30 ListenerRule: Type: AWS::ElasticLoadBalancingV2::ListenerRule Properties: ListenerArn: !Ref LoadBalancerListener Priority: 1 Conditions: - Field: path-pattern Values: - / Actions: - TargetGroupArn: !Ref TargetGroup Type: forward Outputs: TargetGroup: Value: !Ref TargetGroup ServiceUrl: Description: URL of the load balancer for the sample service. Value: !Sub http://${LoadBalancer.DNSName} CanonicalZone: Value: !GetAtt LoadBalancer.CanonicalHostedZoneID DNSName: Value: !GetAtt LoadBalancer.DNSName SecurityGroup: Value: !Ref SecurityGroup