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)