[英]How to add a Route53 alias to an existing Route53 entry?
我在 Route 53 中已经有一个 DNS 条目。在我的 CDK 堆栈中,我想设置一个别名(实际上是一个 CNAME),所以我有一个指向现有条目的新 DNS 条目。 例如,我想让new.example.com
指向existing.example.com
,其中example.com
托管在 Route 53 中并且existing
已经设置好并可以正常工作。
通过 AWS 控制台,我将为new.example.com
创建一个新A
或CNAME
记录,并将其设置为existing.example.com
的别名,这样就可以了,所以我试图在 CDK 中复制它。
在CDK 文档中,它说我可以这样做:
declare const zone: route53.HostedZone;
declare const record: route53.ARecord;
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new targets.Route53RecordTarget(record)),
});
但是,文档没有说明如何填充record
变量。
如果我查看route53.ARecord
文档,似乎没有办法查找现有记录。
我能找到的最接近的是使用其他RecordSet.fromXXX()
函数之一而不是fromAlias
,但是似乎没有可以查找主机名的函数:
...
target: cdkRoute53.RecordTarget.fromValues('target.example.com'), // doesn't work
不幸的是, RecordTarget.fromValues()
只接受 IP 地址。 如果你输入一个主机名,它会告诉你:
无效的资源记录:'致命问题:'target.example.com' 遇到 ARRDATAIllegalIPv4Address(值不是有效的 IPv4 地址)
所以看起来我只能在同一个堆栈中创建目标记录时才能创建别名 - 似乎没有办法加载现有记录,因此您可以将其作为新别名的目标传递.
我错过了什么?
由于这个答案,我同时找到了解决方法。 从那时起,他们添加了缺少的功能,但看起来他们没有提供查找功能,因此解决方法仍然适用。
解决方案是提供一个bind()
function 而不是提供必要的信息:
const route53entry = new cdkRoute53.ARecord(this, 'dns', {
recordName: 'new.example.com',
zone: hostedZone,
target: cdkRoute53.RecordTarget.fromAlias({
bind: () => ({
dnsName: 'existing.example.com',
hostedZoneId: hostedZone.hostedZoneId,
}),
}),
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.