如何获取AWS Route53托管区域ID? [英] How to fetch the AWS Route53 hosted zone id?

查看:148
本文介绍了如何获取AWS Route53托管区域ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Amazon Services及其API的新手.

I am newbie to Amazon Services and their API.

使用Amazon route53Clinet类,我知道有一个方法getHostedZone,它根据ID获取托管区域信息.但是我有一个域名,我需要获取托管的区域ID可能是基于提供的域名吗?我怎样才能做到这一点?

Using Amazon route53Clinet class, I know there is a method getHostedZone which get the Hosted Zone information on the basis of ID. But I have a case where I have the domain name and i need to fetch the hosted zone id may be on the basis of the provided domain name? How can i do that?

推荐答案

您可以使用listHostedZoneslistHostedZonesByName询问有关托管区域的服务.

You can use listHostedZones or listHostedZonesByName to interrogate the service about your hosted zones.

但是...您确实已经需要知道托管区域ID(存储或缓存它),因为有可能在Route 53中为完全相同的域创建多个托管区域...并且如果您的代码通过域名盲目搜索托管区域,您可能最终会修改错误的域名……尤其是如果您陷入假设只有一个匹配项的反模式陷阱中,因此总是选择第一个匹配项.

However... You really need to already know the hosted zone ID -- store or cache it -- because it's possible to create more than one hosted zone in Route 53 for exactly the same domain... and if your code blindly searched for the hosted zone by domain name, you could end up modifying the wrong one... particularly if you fall into the antipattern trap of assuming only one match is possible, and therefore you always select the first match.

简单部署的每个域名只有一个托管区域,但是您可能拥有多个托管区域的原因可能包括私有托管区域(仅可从VPC内部访问)或重复的公共托管区域(在此区域进行DNS重建)或硬性转换.路由53允许您使用4个不同的名称服务器创建第二个(或第三个等)托管区域.

Simple deployments will only have one hosted zone for each domain name, but reasons you might have more than one would include private hosted zones (accessible only from inside your VPC) or duplicate public hosted zones, where you are doing a DNS rebuild or hard cutover. Route 53 allows you to create a second (or third, etc.) hosted zone with 4 different name servers.

当然,在本地拥有此信息也很有意义,以避免发出不必要的API请求,这可能会浪费时间和金钱.您可能已经注意到,托管区域ID在控制台中也可见.

Also, of course, it makes sense to have this information locally to avoid making unnecessary API requests, which can cost time and money. The hosted zone id is, as you likely noticed, also visible in the console.

这篇关于如何获取AWS Route53托管区域ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆