AWS Route 53 - 通过域名获取托管区域?

AWS Route 53 - Get hosted zone by domain name?

有没有办法通过域名检索托管区域?

我认为使用 listHostedZonesByName( 'pagefoo.io' ) 可以解决问题,但它 returns 不相关的结果:pagefoo.net、pagefoo.org 而不仅仅是 pagefoo.io .

Array
(
    [0] => Array
        (
            [Id] => /hostedzone/XXXXXXXXXXXX
            [Name] => pagefoo.io.
            [CallerReference] => XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
            [Config] => Array
                (
                    [PrivateZone] => 
                )

            [ResourceRecordSetCount] => 5
        )

    [1] => Array
        (
            [Id] => /hostedzone/XXXXXXXXXXXX
            [Name] => pagefoo.net.
            [CallerReference] => XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
            [Config] => Array
                (
                    [PrivateZone] => 
                )

            [ResourceRecordSetCount] => 6
        )

    [2] => Array
        (
            [Id] => /hostedzone/XXXXXXXXXXXX
            [Name] => pagefoo.org.
            [CallerReference] => XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
            [Config] => Array
                (
                    [PrivateZone] => 
                )

            [ResourceRecordSetCount] => 4
        )

)

使用 aws-cli route53 接口,我调用了 list-hosted-zones-by-name。它返回了我所有的区域。

$ aws route53 list-hosted-zones-by-name
{
    "HostedZones": [
        (lots of output here)
    ], 
    "IsTruncated": false, 
    "MaxItems": "100"
}

然后我将 --dns-name domain.com 添加到查询中,它返回了我预期的结果:

$ aws route53 list-hosted-zones-by-name --dns-name domain.com
{
    "HostedZones": [
        {
            "ResourceRecordSetCount": 7, 
            "CallerReference": "12345abcde", 
            "Config": {
                "Comment": "HostedZone created by Route53 Registrar", 
                "PrivateZone": false
            }, 
            "Id": "/hostedzone/AABBCCDD", 
            "Name": "domain.com."
        }
    ], 
    "DNSName": "domain.com", 
    "IsTruncated": false, 
    "MaxItems": "100"
}

你没有说你使用的是什么语言,但调用都是相似的,因为它是一个 API 响应。如果您需要特定 SDK 的帮助,您应该包括语言和调用它的代码。但假设您的输出来自 Javascript、it looks like this is the proper call:

route53.listHostedZonesByName({ DNSName: 'domain.com' }, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});