Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ecs-patterns): omiting cluster and specifying only vpc results in an error #18519

Open
madeline-k opened this issue Jan 18, 2022 · 2 comments
Open
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@madeline-k
Copy link
Contributor

What is the problem?

The ecs-patterns README states that 'Instead of providing a cluster you can specify a VPC and CDK will create a new ECS cluster.' However, omiting the cluster prop and only provided a vpc results in an error. And there is not clear direction on how to do this properly.

So far I have noticed this issue with the following constructs. It might apply to more.

  • NetworkMultipleTargetGroupsEc2Service
  • ApplicationMultipleTargetGroupsEc2Service
  • ApplicationLoadBalancedEc2Service

This might just be a miss in the documentation, and not missing functionality. I will need to dive deeper into this to find out.

Reproduction Steps

Synthesize and app with this sample code:

    const stack = new Stack();
    const vpc = new Vpc(stack, 'VPC');

    const service = new ApplicationMultipleTargetGroupsEc2Service(stack, 'Service', {
      vpc,
      memoryLimitMiB: 1024,
      taskImageOptions: {
        image: ContainerImage.fromRegistry('test'),
      },
    });

What did you expect to happen?

No errors, and it synthesizes an ECS service with a cluster created by the CDK.

What actually happened?

I get this error:

      [Default/Service/Service] Cluster for this service needs Ec2 capacity. Call addXxxCapacity() on the cluster.

CDK CLI Version

1.139.0

Framework Version

No response

Node.js Version

12.22.7

OS

MacOS

Language

Typescript

Language Version

No response

Other information

No response

@madeline-k madeline-k added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 18, 2022
@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Jan 18, 2022
@madeline-k madeline-k changed the title (ecs-patterns): omiting cluster and specifying only vpc for (ecs-patterns): omiting cluster and specifying only vpc results in an error Jan 18, 2022
mergify bot pushed a commit that referenced this issue Jan 19, 2022
I removed 3 tests that seem pointless, but I opened an issue to investigate further: #18519 

It really seems like the scenario they were testing (omiting the cluster and only providing vpc) is not a working scenario anyway. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@peterwoodworth peterwoodworth added effort/medium Medium work item – several days of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 19, 2022
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
I removed 3 tests that seem pointless, but I opened an issue to investigate further: aws#18519 

It really seems like the scenario they were testing (omiting the cluster and only providing vpc) is not a working scenario anyway. 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@madeline-k madeline-k removed their assignment Mar 22, 2022
@michaeldrey
Copy link
Contributor

This looks like an issue with the getDefaultCluster function here.

  protected getDefaultCluster(scope: Construct, vpc?: IVpc): Cluster {
    // magic string to avoid collision with user-defined constructs
    const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
    const stack = cdk.Stack.of(scope);
    return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
  }

The new Cluster declaration is a valid reference if we were creating a fargateService, which is probably why it wasn't caught till runtime; however, since we're creating an Ec2 service we need to specify the capacity type which honestly leads into a bigger discussion as we would need to pass in an ASG and ASG provider.

This function is repeated in all base ec2 constructs. I'll keep digging into this

@XTEKiyZRLr8UsiQN
Copy link

XTEKiyZRLr8UsiQN commented Feb 5, 2023

+1, this construct is unusable without a provided cluster. It seems like the intent was to use capacity_provider_strategies but that is not in use right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

No branches or pull requests

4 participants