如何通过Amazon Route53将请求按地区路由?

huangapple go评论73阅读模式
英文:

How to route requests regionally through Amazon Route53?

问题

我有3个相同的Web服务器分布在北美(NA)、欧洲(EU)和亚洲(Asia)这3个主要地区。响应时间对这个系统至关重要,因此,我希望将对这个Web服务器的请求路由到距离请求源最近的实例。如何在Amazon Route53上的DNS级别实现这一点?

我尝试过的方法

  1. 我尝试创建一个包含所有3个IP地址的ResourceRecordSet,但是我只能为每个ResourceRecordSet设置一个GeoLocation
  2. 我尝试创建3个ResourceRecordSet,将它们的GeoLocation.ContinentCode分别设置为NAEUAS,并将它们的ResourceRecords设置为相应的IP地址。然而,无论请求的来源如何,所有发送到该域的请求都被路由到相同的实例。
英文:

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?

What I tried

  1. I tried to create a ResourceRecordSet with its ResourceRecords containing all 3 IP addresses. However, I can set one GeoLocation per ResourceRecordSet.
  2. I tried to create 3 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.

答案1

得分: 3

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:

  • Create 3 records with the same Record Name
  • Select a Routing Policy of Latency
  • For each resource, select the Region where the target is located -- it will route based on the latency from the user requesting the DNS resolution to the selected Region
  • It also wants a Record ID that is simply your reference for the target

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

英文:

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:

  • Create 3 records with the same Record Name
  • Select a Routing Policy of Latency
  • For each resource, select the Region where the target is located -- it will route based on the latency from the user requesting the DNS resolution to the selected Region
  • It also wants a Record ID that is simply your reference for the target

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

huangapple
  • 本文由 发表于 2023年5月29日 17:06:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356002.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定