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

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

问题描述

我是亚马逊服务及其 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 重建或硬切换.Route 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天全站免登陆