Skip to content

ApplicationLoadBalancedFargateService does not work with existing VPC

0

I am trying to create ECS service using the example provided in the page https://docs.aws.amazon.com/cdk/v2/guide/ecs_example.html. It works fine if a VPC is created as part of the code. But if I use an existing VPC, the tasks are not coming up.

export class FargateExistingVpcStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const vpc = ec2.Vpc.fromLookup(this, 'DefaultVPC', { isDefault: true });

    const cluster = ecs.Cluster.fromClusterAttributes(this, "MyCluster", {
      clusterName: 'JobCluster',
      vpc: vpc,
      securityGroups: []
    });

    //clusterArn Create a load-balanced Fargate service and make it public
    new ecs_patterns.ApplicationLoadBalancedFargateService(this, "MyFargateService", {
      cluster: cluster, // Required
      desiredCount: 1, // Default is 1
      taskImageOptions: { image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample") },
      publicLoadBalancer: true, // Default is true,
    });  
  }
}

What could be the possible reasons that tasks are not coming up?

  • for task to be running desire count should be 0. Also check the subnets which you are using for creating service. Check if the task definition is able to pick the image

  • for task to be running desire count should be 0. Also check the subnets which you are using for creating service. Check if the task definition is able to pick the image

  • I am not clear why desire count should be 0. I see that tasks are running so it means the task definition is able to pick the image. The issue is task are not stable, they do not go to healthy state from pending state.

1 Answer
0

What network mode is your task definition configured to use? Does your default VPC allow access to the Internet? To access the image from ECR, you'll either need Internet access from your VPC or create a private link

answered 3 years 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.

Relevant content