Skip to content

Instantly share code, notes, and snippets.

@pmarques
Created April 15, 2019 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarques/2e987f6553486e526266d8be1af53ebe to your computer and use it in GitHub Desktop.
Save pmarques/2e987f6553486e526266d8be1af53ebe to your computer and use it in GitHub Desktop.
Use AWS LoadBalancer V2 to redirect traffic.
---
Resources:
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow http to client host
VpcId: "vpc-1"
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
PublicLoadBalancerBackend:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: "redirectlb"
Scheme: "internet-facing"
SecurityGroups:
- !Ref SecurityGroup
Subnets:
- "subnet-az1"
- "subnet-az2"
PublicLoadBalancerHttpRedirectListener:
Type: AWS::ElasticLoadBalancingV2::Listener
DependsOn:
- PublicLoadBalancerBackend
Properties:
DefaultActions:
# https://docs.aws.amazon.com/elasticloadbalancing/latest/APIReference/API_RedirectActionConfig.html
- RedirectConfig:
Host: "some.random.fqdn" # "#{host}"
Path: "/path" # "#{path}"
Port: 80 # 443
Protocol: "HTTP" # "HTTPS"
Query: "test=1" # #{query}"
StatusCode: HTTP_301
Type: redirect
LoadBalancerArn: !Ref 'PublicLoadBalancerBackend'
Port: 80
Protocol: HTTP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment