From the Load Balancer Lister configuration page, in the AWS Console it allows you to create a listener with a Default Action as shown here:
The Fixed Response option allows you to specify an http return code and a body:
Below is sample known-valid CloudFormation. Not sure how to edit this to support non-forwarding operations.
MyServicesLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref MyServicesLoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: forward
TargetGroupArn: !Ref MyServicesTargetGroup
How do I do this with CloudFormation? The documentation here seems to suggest only the Forward rule is supported in CloudFormation.
Thanks
AWS::ElasticLoadBalancingV2::Listener ForwardConfigInformation for creating an action that distributes requests among one or more target groups. For Network Load Balancers, you can specify a single target group. Specify only when Type is forward .
Application Load Balancers provide native support for HTTP/2 with HTTPS listeners. You can send up to 128 requests in parallel using one HTTP/2 connection. You can use the protocol version to send the request to the targets using HTTP/2.
The rules that you define for your listener determine how the load balancer routes requests to the targets in one or more target groups. Each rule consists of a priority, one or more actions, and one or more conditions.
You must specify either subnets or subnet mappings, but not both. To specify an Elastic IP address, specify subnet mappings instead of subnets. [Application Load Balancers] You must specify subnets from at least two Availability Zones. [Application Load Balancers on Outposts] You must specify one Outpost subnet.
Not possible yet. It has been requested on the forums but no ETA.
According to the Release History of AWS CloudFormation, the feature was added on Nov 19, 2018. This should replicate the fixed response you shown with the console pictures.
MyServicesLoadBalancerListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref MyServicesLoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- Type: fixed-response
FixedResponseConfig:
ContentType: "text/plain"
MessageBody: "You've reached the listener! Congrats!"
StatusCode: "503"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With