How would I specify the subnets for an ALB created by ApplicationLoadBalancedFargateService?

0

I'm using the ApplicationLoadBalancedFargateService construct to deploy ECS services. I have a new requirement to specify the subnets where the tasks and ALBs are instantiated. Tasks were easy with taskSubnets property on ApplicationLoadBalancedFargateServiceProps, however I can't seem to find a way to specify subnets for the ALBs. The construct is currently placing an ALB on each public subnet, which I don't want in this case.

Any suggestions?

Many Thanks, Bryan

1 Answer
0

Hello.

How about specifying your own ALB with the parameter "loadBalancer"?
I thought that if you created your own ALB, you could choose any subnet you like.
https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs_patterns.ApplicationLoadBalancedFargateService.html

The code will look like this:

    const loadBalancedFargateService = new ecsp.ApplicationLoadBalancedFargateService(this, 'SampleWebService', {
      cluster,
      memoryLimitMiB:512,
      desiredCount:1,
      cpu:256,
      taskImageOptions: {
        image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
      loadBalancer:alb, // <-- your ALB
      openListener:false,
    });
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions