'AWS CDK ApplicationLoadBalancedFargateService in private (isolated) subnet

I'm trying to create a cdk stack containing an ApplicationLoadBalancedFargateService (docs). I want it placed in my VPC which exclusively contains private subnets.

When I try to deploy my stack I get an error message saying:

Error: There are no 'Public' subnet groups in this VPC. Available types: Isolated

Which well... in theory is correct, but why does it break my deployment?

Here an extract of my code my code:

    // Get main VPC and subnet to use
    const mainVpc = ec2.Vpc.fromLookup(this, 'MainVpc', {
      vpcName: this.VPC_NAME
    });

    // Fargate configuration
    const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this,
      'CdkDocsFargateService', {
      serviceName: 'docs-fargate-service',
      memoryLimitMiB: 512,
      desiredCount: 1,
      cpu: 256,
      vpc: mainVpc,
      taskImageOptions: {
        image: ecs.ContainerImage.fromRegistry(this.IMAGE_NAME),
        containerPort: 80,
      },
    });

I was able to achieve the desired outcome manually from the management console. What am I doing wrong when using CDK?



Solution 1:[1]

I solved the problem by setting publicLoadBalancer: false in the properties of the ApplicationLoadBalancedFargateService.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ga97dil