‫So now let's talk about
‫the weighted routing policy.
‫The idea is that you can have a percentage of requests
‫you can control to go to a specific resource
‫thanks to weights.
‫So, put it simply in the diagram,
‫we have Amazon route 53,
‫and then we have three EC2 instance
‫that have been assigned different weights,
‫so 70, 20, and 10.
‫In my example, these weights sum up to 100,
‫but you don't have to in the real life, okay?
‫But what this means that 70%
‫of the DNS responses from Amazon as on route 53
‫are going to be redirecting to the first EC2 instance,
‫then 20% to the second and 10% to the third.
‫So what we have to do in our weight is to assign each record
‫a relative weights.
‫And then the traffic percentage is going to be sent
‫to each record, as just the weight of the record
‫divided by the sum of all the weights of all the records
‫which is like a percentage of all the weights, okay?
‫The weights don't need to sum up to 100,
‫they're just indicative of how much
‫we want to send to this instance,
‫compared to all the other records in your DNS name.
‫So to make this work,
‫the DNS records must have the same name and type,
‫and you can associate them with health checks,
‫although we haven't seen with health checks are again yet,
‫but we'll have a look at them very, very soon.
‫Now the use cases for a weighted routing policy
‫is pretty obvious, is to do for example, load balancing,
‫maybe across different regions, or to test a new application
‫version by sending a small amount of traffic to it,
‫and so on.
‫And then if you're sending to sort of a weight of zero,
‫then you're going to stop sending traffic
‫to a specific resource, so you can shift weight over time.
‫And if all the resource records will have a weight of zero,
‫then all the records will be returned with equal weights.
‫So let's have a look in the console
‫to see how that works.
‫So let's create a new record,
‫and this one is going to be called
‫weighted.stephanethetaccher.com.
‫It's an A record, and the routing policy
‫is going to be weighted.
‫So first for the first value, let's enter the one
‫from the ap-southeast-1,
‫and the weights I'm going to assign to it
‫this time is going to be 10, okay?
‫So it's very, very small weights.
‫For the TTL, I'm going to set it to something really low,
‫three seconds to just show you the impact of weighted.
‫But obviously, this is not a TTL
‫you would use in real life.
‫So as we can see,
‫we can associate a health check with it,
‫but for now we won't.
‫And we have a record ID that we can set.
‫And this is to identify this specific record
‫within the weighted record sets.
‫So for this one, I got this instance from the southeast,
‫I'm just going to write southeast.
‫Okay, and then we can add another record.
‫And again, we're going to use the same
‫weighted.stephanetheteache.com, okay?
‫And the routing policy is going to be weighted.
‫And the value of which is going to be
‫the one from us-east-1.
‫So I'm going to copy this IP and paste it here.
‫The weight is going to be on this time 70.
‫So we're going to send 70% of the traffic to us-east-1,
‫and then the record ID is US East.
‫Great, and the TTL again, three seconds.
‫And one last record we're going to add, so again, weighted,
‫and then the value of which is going to be
‫eu-central-1, in here.
‫And I'm going to send it as a weighted record.
‫I'm going to send 20 as weights, and the record ID
‫is going to be EU okay.
‫And the TTL three seconds.
‫So now let's go ahead and create these records.
‫And as we can see, we now have three records
‫in this table, okay?
‫So this is why it's different from, for example,
‫a simple record has two values,
‫here, we have three records and each record
‫has one value as an answer,
‫but we have a weight of 10, 20 and 70.
‫So if I go to the URL now,
‫if I go to weighted.stephanetheteacher.com and press Enter,
‫I'm getting a first response from the us-east-1a
‫which makes sense because, well,
‫this is where 70% of the traffic is supposed to be going
‫okay, to this region.
‫But if I refresh and I need to refresh
‫maybe every three seconds, at some points,
‫I should be getting a response from another region.
‫And this is just based on weight,
‫so this is the (indistinct) behind the weighted resources.
‫So as you can see, this one is not changing a lot,
‫so let's do a dig command just to show you
‫the output of what it is,
‫so dig weighted.stephanetheteacher.com.
‫and here we get a TTL of three and the answer is,
‫I think still the one from the us-east-1,
‫But so let's try to issue one more,
‫and see if we get any luckier.
‫So the weight of 70 definitely is a big weight.
‫Okay, but here as we can see, we just got an answer,
‫and this one is a different IP, 3.70.14,
‫which is corresponding to the weight of 20.
‫So as we can see, weighted does exactly
‫what it's supposed to do, it's redirecting
‫most of the queries into the one that has the most weight,
‫but from time to time, you will get other answers, okay?
‫And so on.
‫So this is something you can practice in your web browser
‫as well as we can see, cool.
‫I just get redacted into eu-central-1c.
‫So that's it for this lecture,
‫and hopefully it shows you the power of weighted records.
‫I hope you liked it, and I will see you in the next lecture.