AWS just dropped a super useful feature for REST APIs in Amazon API Gateway: Routing Rules for Custom Domains.
This means you can now route incoming requests based on:
β
HTTP header values
β
URL base paths
β
Or a combination of both
And you can do it without writing a single line of code or managing extra proxies. Letβs break it down with a real-world example.
π§ͺ Use Cases Made Easy
This new feature unlocks flexible patterns like:
- π A/B testing (e.g., send 10% of users to a beta API)
- π Version-based routing (/v1, /v2)
- π§ Dynamic backend selection based on request headers
π― Real Example:
api.example.com
Letβs say you have 3 different versions of your API:
API Type | API ID | Stage |
---|---|---|
Stable v1 | v1-api-id |
prod |
New v2 | v2-api-id |
prod |
Staging Beta | staging-api-id |
beta |
π§ Routing Rules Configuration
Priority | Condition | Route To |
---|---|---|
1 | Header x-test-group = beta
|
staging-api-id , beta
|
2 | Path starts with /v2
|
v2-api-id , prod
|
3 | Path starts with /v1
|
v1-api-id , prod
|
π₯ API Gateway will evaluate rules by priority (lower number wins).
π₯ Example Requests
GET /v1/users
- No headers
- β Routed to v1-api-id (prod)
GET /v2/products
- No headers
- β Routed to v2-api-id (prod)
GET /anything + header x-test-group: beta
- β Routed to staging-api-id (beta)
π§ Why This Rocks
- No Lambda or Nginx-based routing needed
- Keeps your API infra clean and modular
- Works for both public and private REST APIs
- Compatible with existing API mappings
π οΈ How to Set It Up
Go to API Gateway > Custom Domains
Click on your domain (e.g. api.example.com)
Define Routing Rules:
- Set Priority
- Add Conditions (headers, paths)
- Choose Target REST API + Stage
Thatβs it β API Gateway takes care of the logic from there!
β Final Thoughts
This update brings a long-missing feature to REST APIs in API Gateway β one that was previously only achievable via Lambda workarounds or heavy reverse proxy setups.
Now you can do smart, rule-based routing natively β clean, fast, and fully managed.
π¬ Have you tried the new routing rules yet? Planning to use it for versioning or blue/green deployments? Letβs chat below!
Top comments (0)