[英]AWS CDK, creating an alias record for an existing hosted zone in Route53
[英]How to create hosted zone in AWS CDK?
您好,我正在使用 AWS CDK 為我使用 ELB 和 ECS 部署的應用程序創建托管區域。 我熟悉雲的形成,下面是我的示例雲形成模板。
LocationServiceRoute53:
Type: "AWS::Route53::RecordSet"
Properties:
HostedZoneId: !ImportValue "infra-r53-zones-region::PrivateZoneId"
Comment: "Zone alias targeted to LoadBalancer"
Name:
!Join
- "."
- - "app"
- "locationservices"
- !ImportValue "infra-r53-zones-region::PrivateZoneName"
Type: "A"
AliasTarget:
# yamllint disable-line rule:line-length
HostedZoneId: {'Fn::ImportValue': !Sub 'location-agent-alb${StackSuffix}::MWSLoadBalancerHostedZoneId'}
# yamllint disable-line rule:line-length
DNSName: {'Fn::ImportValue': !Sub 'location-agent-alb${StackSuffix}::MWSLoadBalancerDNSName'}
我正在用 CDK 重寫如下。
hostedZone = route.HostedZone.from_hosted_zone_attributes(self, 'HostedZone', hosted_zone_id='some id ', zone_name='zone name')
recordName = 'record name'
targetAlias = route.AddressRecordTarget.from_alias(alias_target )
route.ARecord(self, id='AliasRecord', zone = hostedZone, comment='Zone alias targeted to LoadBalancer',
record_name=recordName, target=targetAlias)
這是拋出AttributeError: 'ApplicationLoadBalancer' object has no attribute 'dns_name'
有人可以幫我寫嗎? 任何幫助,將不勝感激。 謝謝
這對我有用。
hostedZone = route.HostedZone.from_hosted_zone_attributes(self, 'HostedZone', hosted_zone_id='some id ', zone_name='zone name')
recordName = 'r name'
route.ARecord(self, id='AliasRecord', zone = hostedZone, comment='Zone alias targeted to LoadBalancer',
record_name=recordName, target = route.RecordTarget.from_alias(route_targets.LoadBalancerTarget(lb)))
我拿了我的工作代碼並適應了你的情況:
const cdk = require('@aws-cdk/core')
const route53 = require('@aws-cdk/aws-route53')
const alias = require('@aws-cdk/aws-route53-targets')
const hostedZoneId = cdk.Fn.importValue(`infra-r53-zones-region::PrivateZoneId`)
const zone = route53.HostedZone.fromLookup(this, hostedZoneId, {domainName: 'xxxx-xxx.com'});
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.LoadBalancerTarget(<loadBalancer>)),
recordName: <your_domain_name>
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.