您好,我正在使用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'
有人可以帮我写吗?任何帮助,将不胜感激。谢谢
答案 0 :(得分:1)
我拿了我的工作代码并适应您的情况:
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>
});
答案 1 :(得分:0)
这对我有用。
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)))