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)