https://pulumi.com logo
#general
Title
# general
s

swift-dinner-29731

06/25/2019, 7:55 AM
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

gentle-diamond-70147

06/25/2019, 3:57 PM
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

swift-dinner-29731

06/25/2019, 4:00 PM
@gentle-diamond-70147 Thanks for reply. I can't hardcoding it. But this code works -
tg.loadBalancer.loadBalancer.zoneId
g

gentle-diamond-70147

06/25/2019, 4:03 PM
Oh, I see. Sorry I misunderstood. I thought you were asking about the
hostedZoneId
for the record itself, not the aliases. 👍
l

lemon-student-18495

06/26/2019, 9:04 PM
@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?
2 Views