Hi, I’m trying to create a app load balancer with ...
# typescript
f
Hi, I’m trying to create a app load balancer with a target with a target group to a docker image, but its only working for me if the docker image listens on port 80, I need it to work on a diff port... (Its most probably a stupid config I don’t understand...) if someone can help please.
this is the code
Copy code
const alb = new awsx.lb.ApplicationLoadBalancer("load-balancer");

alb.createListener("http-listener", {
  port: 80,
  protocol: "HTTP",
  defaultAction: {
    type: "redirect",
    redirect: {
      protocol: "HTTPS",
      port: "443",
      statusCode: "HTTP_301",
    },
  },
});

const target = alb.createTargetGroup("target-group", {
  port: 80,
  protocol: "HTTP",
  healthCheck: {
    path: "/healthCheck",
    interval: 30,
    timeout: 20,
  },
});

const httpslistener = target.createListener("https-listener", {
  port: 443,
  protocol: "HTTPS",
  certificateArn: cert.arn,
});

new awsx.ecs.FargateService("server", {
  desiredCount: 2,
  taskDefinitionArgs: {
    containers: {
      server: {
        image: awsx.ecs.Image.fromPath("server", "./app"),
        memory: 512,
        portMappings: [target],
      },
    },
  },
});

export default httpslistener;
b
@freezing-accountant-92268 you need to set the container port in your `portMappings`: https://www.pulumi.com/registry/packages/awsx/api-docs/ecs/fargateservice/#containerport_nodejs
what versions of awsx are you using?
f
0.40.0
b
you should be able to set the containerPort there
f
yes I tried but I get an error that the containerPort and hostPort need to be the same
b
w
There are some other confusing things going on with the docs (and possibly the code) with how the ecs.fargateService does the port mapping.
b
i would love to have issues filed for that
w
I’m working on digging up the details
in the example given there the portMappings property takes an array with an object containing
containerPort
and
targetGroup
but the typescript sdk complains if you actually try passing that in
Copy code
Type '{ containerPort: number; targetGroup: any; }' is not assignable to type 'Input<PortMapping> | ContainerPortMappingProvider'.
  Object literal may only specify known properties, and 'targetGroup' does not exist in type 'Input<PortMapping> | ContainerPortMappingProvider'.
b
yeah that definitely needs an issue 🙂
w
it’s repeated elsewhere in the docs too
I’m particularly confused by how the whole thing is supposed to work. We are trying to wire together a listener/targetGroup to the ecs fargate service running a docker container on some arbitrary port. How is the portMapping supposed to be doing it’s magic to make the docker host map to the container’s port?
There are three ports involved here: 1. the targetGroup’s port (where the listener will be sending the traffic) 2. the ecs/docker host port (I’m assuming this needs to match the targetGroup port) 3. the docker container’s port (and I’m assuming the portMapping property is supposed to map this to the docker host port)
how does awsx figure out by passing in a listener or targetGroup into the portMapping property how to map port 2 (docker host) to port 3 (docker container)?
b
I’m juggling a few things here, set a reminder to come back to ths when I can absorb/consume it properly. sorry for the delay
a
@billowy-army-68599 any progress on this, I'm having the same issue.
b