Hi, How to setup route 53 alias to load balancer? ...
# general
s
Hi, How to setup route 53 alias to load balancer? I used next code :
Copy code
const nlb = new awsx.elasticloadbalancingv2.NetworkLoadBalancer("some-nlb", {external: true });
 const tg = nlb.createTargetGroup("some-tg", { port: 3000 });
 const listener = tg.createListener("some-http-listener", { port: 80 });
const listener2 = tg.createListener('https-listener', {
    certificateArn: certificate.arn,
     loadBalancerArn: nlb.arn,
    port: 443,
    protocol: "TLS",
    sslPolicy: "ELBSecurityPolicy-2016-08"
}); 

let service = new awsx.ecs.FargateService("some-app", {
    desiredCount: 1,
    taskDefinitionArgs: {
        containers: {
            myapp: {
                image: awsx.ecs.Image.fromPath("app", "../"),
                memory: 512,
                portMappings: [listener],
            },
        },
    },
});

const webDnsRecord = new aws.route53.Record("webDnsRecord", {
    name: domain,
    type: "A",
    zoneId: hostedZoneId,
    aliases: [{
        evaluateTargetHealth: true,
        name: listener.endpoint.hostname,
        zoneId: listener.loadBalancer.zoneId,   <!!! problem here>
    }],
}, { dependsOn: sslCertValidationIssued });
How to get zoneId for elastic load balacer ? Because in this code I had this error : error: awsroute53/recordRecord resource 'webDnsRecord' has a problem: "alias.0.zone_id": required field is not set
g
You must provide the Zone ID that is set by Route53.
You can do this by hardcoding it, using a config value (e.g.
new pulumi.Config().require("zoneId")
), or you can do a look up to get the Zone ID based on the zone name.
s
@gentle-diamond-70147 Thanks for reply. I can't hardcoding it. But this code works -
tg.loadBalancer.loadBalancer.zoneId
g
Oh, I see. Sorry I misunderstood. I thought you were asking about the
hostedZoneId
for the record itself, not the aliases. 👍
l
@gentle-diamond-70147 -- how would we do a lookup for the hostedZoneId? I see there is get_zone (https://github.com/pulumi/pulumi-aws/blob/master/sdk/python/pulumi_aws/route53/get_zone.py) but not sure how to use that value properly. Could you provide an example for python possibly?