How can I send custom HTTP responses for specific URLs from an Application Load Balancer?
Last updated: 2019-12-30
I want to forward custom HTTP responses and drop client requests for specific URLs. How can I send custom HTTP responses for specific URLs from an Application Load Balancer?
You can use fixed-response actions to drop client requests and return a custom HTTP response. You can use this action to return a 2XX, 4XX, or 5XX response code and an optional message.
To add a rule with a fixed-response action on your Application Load Balancer's listener:
- Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
- On the navigation pane, from LOAD BALANCING, choose Load Balancers.
- Select your load balancer and choose the Listeners tab.
- Choose View/edit rules.
- Choose Add rules (the plus sign) in the menu bar. This action allows you to add Insert Rule icons at every location where you can insert a rule in the priority order.
- Define the rule as follows:
Choose Insert Rule.
(Optional) To configure host-based routing, choose Add condition, Host is. Enter the hostname (for example, *.example.com), and then choose the check mark.
(Optional) To configure path-based routing, choose Add condition, Path is. Enter the path pattern (for example, /img/*), and then choose the check mark.
To add a fixed-response action, choose Add action, Return fixed response. Enter a response code and optional response body, and then choose the check mark.
(Optional) To change the order of the rule, use the arrows. The default rule always has the last priority.
- Choose Save.