AWS加权流量策略未按预期生效,请求排查流量分配异常
Hey there, let's break down why your weighted Route 53 record set isn't distributing traffic as you expected. I’ve debugged similar issues multiple times, so here are the key areas to investigate:
1. Double-Check Your Record Set Configurations
First, confirm the basics are correct:
- Ensure both records live in the same hosted zone for
example.com, have exactly the same name (www.example.com—watch out for accidental trailing dots or typos), and are both TypeA. - Verify the weights are set properly: one record with
Weight = 1pointing to192.0.2.11, and the other withWeight = 3pointing to192.0.2.12. It’s easy to mix up values when creating records!
2. DNS Caching Is Likely Interfering
DNS caching at any layer can skew your results:
- Local/browser cache: Clear your browser’s cache or use incognito mode. On your machine, flush the DNS cache:
- Windows: Run
ipconfig /flushdnsin Command Prompt - macOS: Run
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponderin Terminal
- Windows: Run
- DNS resolver cache: Try querying with a public DNS server like
8.8.8.8or1.1.1.1to rule out issues with your local resolver. Use commands likedig @8.8.8.8 www.example.comornslookup www.example.com 1.1.1.1to confirm both IPs are being returned.
3. Weighted Routing Is Probabilistic, Not Strict
Route53’s weighted routing uses statistical probability, not a rigid 1:3 split for small request counts. If you only send 4 requests, you might not get exactly 1 hit to 192.0.2.11 and 3 to 192.0.2.12—that’s normal. To see the expected 25%/75% split, you need to send a large number of requests (hundreds or more). For example, run this loop in Terminal to test:
for i in {1..100}; do curl -s -o /dev/null -w "%{remote_ip}\n" www.example.com; done | sort | uniq -c
This will show you how many times each IP was hit, and the ratio should get closer to your expected split as you increase the number of requests.
4. Check for Conflicting Routing Policies
Make sure you haven’t accidentally applied another routing policy to these records. Route53 only allows one routing policy per record set group. If you previously set up geolocation, failover, or latency routing for www.example.com, it could override the weighted routing behavior. Confirm both records are explicitly set to use the Weighted routing policy.
5. Health Checks Might Be Redirecting Traffic
If you’ve attached health checks to either record, a failed health check will cause Route53 to stop sending traffic to that endpoint. For example, if 192.0.2.12 fails its health check, all traffic will go to 192.0.2.11, and vice versa. Check the health check status in the Route53 console for both endpoints to ensure they’re marked as healthy.
6. Your DNS Resolver Might Ignore Weights
Some enterprise or third-party DNS resolvers ignore DNS weight values and use their own load-balancing logic (like round-robin). Test with a public resolver (as mentioned earlier) to see if the issue is specific to your resolver.
内容的提问来源于stack exchange,提问作者k_vishwanath

