I can create A record in Route53:
But when I use cdk code to do the same thing. It failed. This is the Code:
// ALB names are limited to 32 characters...workaround
let lbNameLength = 28
let truncatedServiceName = props.serviceName.substring(0, lbNameLength)
// Creating an internet facing ALB
const loadBalancer = new elbv2.ApplicationLoadBalancer(this, "alb", {
vpc: props.cluster.vpc,
vpcSubnets: {
subnets: props.cluster.vpc.privateSubnets
},
loadBalancerName: `${truncatedServiceName}-lb`,
idleTimeout: Duration.seconds(3600)
});
// Allowing incoming connections
loadBalancer.connections.allowFromAnyIpv4(ec2.Port.tcp(props.lbPort), "Allow inbound HTTP");
// Creating a listener and listen to incoming requests
const listener = loadBalancer.addListener("listener", {
port: props.lbPort,
protocol: elbv2.ApplicationProtocol.HTTP
});
// Creating a target group that points to the application container (e.g. port 8080)
listener.addTargets("targets", {
port: props.containerPort,
protocol: elbv2.ApplicationProtocol.HTTP,
targets: [service],
healthCheck: {
path: '/health'
}
});
const dnsParams= dnsParameters(this, id)
const magnaHostedZone = route53.HostedZone.fromHostedZoneAttributes(this, 'hostedZone', {
hostedZoneId: dnsParams.hostedZoneId,
zoneName: dnsParams.zoneName
})
// Using alias because load balancer is an AWS resource
new route53.ARecord(this, 'aRecord', {
zone: magnaHostedZone,
target: route53.AddressRecordTarget.fromAlias(new targets.LoadBalancerTarget(loadBalancer)),
recordName: "semantic-search-v2"
});
When I run this typescript cdk code, it occurs this error:
DomainLabelEmpty (Domain label is empty) encountered with 'semantic-search-v2.aws.magna.china.' (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 9f643150-262c-43fc-87ff-800dca172171; Proxy: null)
I don't know what does 'DomainLabelEmpty' mean.
BTW, all the subnets of my account are private and cannot access the public network.
Thanks in advance for helping me!
Try appending the r53 hosted zone name to the recordName
attribute of ARecord.