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?

Resolution

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:

  1. Open the Amazon Elastic Compute Cloud (Amazon EC2) console.
  2. On the navigation pane, from LOAD BALANCING, choose Load Balancers.
  3. Select your load balancer and choose the Listeners tab.
  4. Choose View/edit rules.
  5. 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.
  6. 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.
  7. Choose Save.

Did this article help you?

Anything we could improve?


Need more help?