Skip to content

CloudFormation support for regex values on load balancer listener rules

0

When editing a LoadBalancer listener rule through the AWS UI, there is an option for the host header to match by a regex value

example

However, looking at the CloudFormation documentation for listener rules, there is no mention of any regex support: https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-elasticloadbalancingv2-listenerrule-hostheaderconfig.html

Moreover, if I create a CloudFormation stack with a listener rule matching by value, and then manually modify it through the UI to use regex instead, and then detect drift on that stack, it appears as if the values were removed, but there is no mention of the new regex values

example2

Is this a new feature that is not yet supported by CloudFormation? And is there any plan to add support for it?

Thank you!

1 Answer
0

Yes, regex matching for host headers in Application Load Balancer listener rules is supported in the AWS console UI, but this capability does not appear to be directly supported in CloudFormation yet.

When you create a listener rule through the AWS console, you have the option to select between "Value matching" and "Regex matching" for host headers. The value matching option allows for wildcards (* and ?), while regex matching allows you to use regular expressions for more complex pattern matching.

The fact that modifying a CloudFormation-created rule to use regex through the UI results in drift detection (showing values were removed but not showing the new regex values) suggests that CloudFormation doesn't currently have a way to represent this feature in templates.

For host header conditions in the console, you can specify:

  • Value matching: Up to 128 characters, not case sensitive, with allowed characters including a-z, A-Z, 0-9, special characters like -_.; and wildcards (* and ?).
  • Regex matching: Up to 128 characters.

While CloudFormation doesn't appear to support regex matching for host headers directly at this time, you might want to check AWS announcements or the CloudFormation roadmap for information about planned support for this feature.

As an alternative, you could consider using transforms for listener rules, which do support regex patterns. Transforms allow you to modify requests before they're routed to targets, including host header rewrites using regular expressions.
Sources
Condition types for listener rules - Elastic Load Balancing
Add a listener rule for your Application Load Balancer - Elastic Load Balancing
Transforms for listener rules - Elastic Load Balancing

answered a year ago

AWS
EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.