How can I route traffic based on a custom HTTP header using an Application Load Balancer?
Last updated: 2020-08-14
I want to perform a specific action on requests based on the value of a custom HTTP header using an Application Load Balancer. How can I do this?
- Create an Application Load Balancer, if you don't already have one.
- Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
- On the navigation pane, under Load Balancing, choose Load Balancers.
- Select your load balancer.
- Choose the Listeners tab.
- Select your HTTP listener, and then choose View/edit rules.
- Choose the Add rules icon (the plus sign), and then choose Insert rule.
- Choose Add condition, and then choose Http header.
- Specify a header name based on the desired action. For example, "Accept."
Note: The maximum size of each header name is 40 characters. The header name is not case-sensitive. Wildcards are not supported.
- Specify the values (comparison strings) of the custom header.
Note: The maximum size of each comparison string is 128 characters. The comparison string is not case-sensitive. The asterisk (*) and question mark (?) wildcard characters are supported.
- Choose Add action, and then select the required action. For example:
Forward – To forward to a different target group.
Return fixed response – To block or provide a custom response to particular clients based on the value of custom header.
- To save the condition, choose the checkmark icon.
- To save the rule, choose Save.