您好,我正在使用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',有人能帮我写一下吗?任何帮助都将不胜感激。谢谢
发布于 2019-12-17 14:36:49
这对我很有效。
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)))发布于 2019-12-17 18:14:42
我采用了我的工作代码,并根据您的情况进行了调整:
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>
});https://stackoverflow.com/questions/59368219
复制相似问题