Is there an easy way using Crosswalk with ECS to s...
# general
d
Is there an easy way using Crosswalk with ECS to specify a container port that is different to the load balancer port of 80?
b
You can do something like the following:
Copy code
const task = new awsx.ecs.FargateTaskDefinition("td", {
  containers: {
    nginx: {
      image: "nginx",
      portMappings: [{protocol: "tcp", containerPort: 80, hostPort: 80}]
    }
  }
})
is that what you mean?
d
yes pretty much! Thanks for the reply. So my container runs on port 5000
Copy code
const alb = new awsx.lb.ApplicationLoadBalancer("backend-ecs-alb");
const listener = alb.createListener("backend-ecs-listener", { port: 80 });

const nginx = new awsx.ecs.FargateService("backend-ecs", {
    taskDefinitionArgs: {
        containers: {
            backend: {
                image: image,
                memory: 128,
                portMappings: [listener],
            },
        },
    },
    desiredCount: 2,
});
do I need to create a specific
FargateTaskDefinition
for this?
b
Copy code
const alb = new awsx.lb.ApplicationLoadBalancer("backend-ecs-alb");
const listener = alb.createListener("backend-ecs-listener", { port: 80 });
const nginx = new awsx.ecs.FargateService("backend-ecs", {
    taskDefinitionArgs: {
        containers: {
            backend: {
                image: image,
                memory: 128,
                portMappings: [{protocol: "tcp", containerPort: 80, hostPort: 80}],
            },
        },
    },
    desiredCount: 2,
});
that should work
d
There’s no mention of port 5000 above ?
b
Then you can swap
containerPort
from
80
to
5000
d
if I remove
portMappings: [listener],
from the taskDefinition, how does the LB get bound to the ECS task?
ok well this worked:
Copy code
import * as awsx from "@pulumi/awsx";

const image = awsx.ecr.buildAndPushImage("backend-ecs", {
    context: "./app",
});

const cluster = new awsx.ecs.Cluster("backend-ecs-cluster");

const alb = new awsx.elasticloadbalancingv2.ApplicationLoadBalancer("backend-ecs-alb", { 
    external: true,
    securityGroups: cluster.securityGroups 
});
const atg = alb.createTargetGroup("backend-ecs-tg", { 
    port: 5000, 
    protocol: "HTTP",
    deregistrationDelay: 0 
});
const web = atg.createListener("web", { 
    port: 80 
});

const appService = new awsx.ecs.FargateService("backend-ecs-fargateservice", {
    cluster,
    taskDefinitionArgs: {
        container: {
            image: image,
            portMappings: [web],
        },
    },
    desiredCount: 1,
});

export const url = web.endpoint.hostname;
b
I was about to say you can use a network loadbalancer:
Copy code
const lb = new awsx.lb.NetworkTargetGroup("nginx", { port: 5000 })
                .createListener("listener", {port: 80});
But your way will work too 🙂
d
ah ok - thanks for your help Piers