I have 3 identical web servers in 3 major regions NA, EU, and Asia. The response time is crucial for this system, therefore, I want the requests to this web server to be routed to the closest instance to the request source. How do I achieve this on the DNS level using Amazon Route53?
ResourceRecordSet
with its ResourceRecords
containing all 3 IP addresses. However, I can set one GeoLocation
per ResourceRecordSet
.ResourceRecordSet
with their GeoLocation.ContinentCode
set to NA
, EU
, and AS
and their ResourceRecords
set to corresponding IP addresses. However, all requests sent to the domain were routed to the same instance, regardless of the request origin.Your requirements seem to match Latency-based routing - Amazon Route 53. This will route users via the connection with the lowest latency, which might not be the closest location geographically due to the placement of high-speed internet connections. You could then use something like Global Latency Test - Bunny Tools to test how it behaves.
To configure Latency-Based Routing:
You can even create these multiple records on a single page by clicking Add Another Record at the bottom of the screen.
To configure the Record Sets via an API call, consult the documentation for your preferred AWS SDK. For example, here is a change_resource_record_sets - Boto3 documentation example for boto3/Python:
response = client.change_resource_record_sets(
ChangeBatch={
'Changes': [
{
'Action': 'CREATE',
'ResourceRecordSet': {
'HealthCheckId': 'abcdef11-2222-3333-4444-555555fedcba',
'Name': 'example.com',
'Region': 'us-east-2',
'ResourceRecords': [
{
'Value': '192.0.2.44',
},
],
'SetIdentifier': 'Ohio region',
'TTL': 60,
'Type': 'A',
},
},
{
'Action': 'CREATE',
'ResourceRecordSet': {
'HealthCheckId': 'abcdef66-7777-8888-9999-000000fedcba',
'Name': 'example.com',
'Region': 'us-west-2',
'ResourceRecords': [
{
'Value': '192.0.2.45',
},
],
'SetIdentifier': 'Oregon region',
'TTL': 60,
'Type': 'A',
},
},
],
'Comment': 'EC2 instances for example.com',
},
HostedZoneId='Z3M3LMPEXAMPLE',
)
print(response)
Or, for the equivalent in the AWS CLI, see: change-resource-record-sets — AWS CLI Command Reference