Created
December 10, 2017 13:22
-
-
Save li0nel/b6fd90ab1ed4d7a7d3e2f0068d8c3f6a to your computer and use it in GitHub Desktop.
CloudFormation template for ALB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # One ALB with two listeners for HTTP and HTTPS | |
| # The HTTP listener will pointed to a specific Nginx container redirecting traffic to HTTPS | |
| # because neither ALB or ELB allow you to handle this through their configuration | |
| LoadBalancer: | |
| Type: AWS::ElasticLoadBalancingV2::LoadBalancer | |
| Properties: | |
| Name: !Ref EnvironmentName | |
| Subnets: !Ref PublicSubnets | |
| SecurityGroups: | |
| - !Ref LBSecurityGroup | |
| Tags: | |
| - Key: Name | |
| Value: !Ref EnvironmentName | |
| LoadBalancerListenerHTTP: | |
| Type: AWS::ElasticLoadBalancingV2::Listener | |
| Properties: | |
| LoadBalancerArn: !Ref LoadBalancer | |
| Port: 80 | |
| Protocol: HTTP | |
| DefaultActions: | |
| - Type: forward | |
| TargetGroupArn: !Ref DefaultTargetGroup | |
| LoadBalancerListenerHTTPS: | |
| Type: AWS::ElasticLoadBalancingV2::Listener | |
| Properties: | |
| LoadBalancerArn: !Ref LoadBalancer | |
| Port: 443 | |
| Protocol: HTTPS | |
| Certificates: | |
| - CertificateArn: !Ref LBCertificateArn | |
| DefaultActions: | |
| - Type: forward | |
| TargetGroupArn: !Ref DefaultTargetGroup | |
| # We define a default target group here, as this is a mandatory Parameters | |
| # when creating an Application Load Balancer Listener. This is not used, instead | |
| # a target group is created per-service in each service template (../services/*) | |
| DefaultTargetGroup: | |
| Type: AWS::ElasticLoadBalancingV2::TargetGroup | |
| Properties: | |
| Name: !Sub ${EnvironmentName}-default | |
| VpcId: !Ref VPC | |
| Port: 80 | |
| Protocol: HTTP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment