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

时间:2015-10-24 19:16:59

标签: php amazon-web-services amazon-route53 aws-php-sdk

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

我认为使用listHostedZonesByName('pagefoo.io')可以解决问题,但它会返回无关的结果: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
        )

)

1 个答案:

答案 0 :(得分:0)

使用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
});