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

(aws-ecs): fromClusterAttributes requires VPC #12468

Closed
mimozell opened this issue Jan 12, 2021 · 6 comments
Closed

(aws-ecs): fromClusterAttributes requires VPC #12468

mimozell opened this issue Jan 12, 2021 · 6 comments
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2

Comments

@mimozell
Copy link

mimozell commented Jan 12, 2021

I'm trying to fetch an ECS cluster based on its name, but security groups (mentioned here) and VPC (at least) are required.

Reproduction Steps

    Cluster.fromClusterAttributes(
        this, 
        "importedCluster",
        ClusterAttributes.builder()
            .clusterName(clusterName)
            .securityGroups(emptyList())
            .build()

What did you expect to happen?

I would expect fromClusterAttributes to have the same behaviour as aws ecs describe-clusters <clusterName>. The API clearly doesn't require you to provide the VPC (or security groups), so why does this?

What actually happened?

Exception in thread "main" java.lang.NullPointerException: vpc is required

Environment

  • CDK CLI Version: 1.78.0 (build 2c74f4c) and 1.83.0 (build 827c5f4)
  • Node.js Version: v12.16.3
  • OS: MacOS
  • Language (Version): Kotlin (openjdk version "11.0.8")

This is 🐛 Bug Report

@mimozell mimozell added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2021
@tscully49
Copy link

We are having the same issue in a different context. In cloudformation, creating a fargate serivice only requires The short name or full Amazon Resource Name (ARN) of the cluster on which to run your service. If you do not specify a cluster, the default cluster is assumed. (from https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html) and I would expect that to have similar behavior here. Instead, for CDK, to create a FargateService construct, I have to find the cluster with this function by passing both the securityGroups and VPC, when it seems a cluster name or ARN should be fine.

@SoManyHs SoManyHs added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jan 20, 2021
@SoManyHs SoManyHs changed the title [ECS]: fromClusterAttributes requires VPC (aws-ecs): fromClusterAttributes requires VPC Jan 20, 2021
@SoManyHs SoManyHs added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 20, 2021
@MrArnoldPalmer MrArnoldPalmer added the effort/medium Medium work item – several days of effort label Feb 22, 2021
@DonDebonair
Copy link

I'm having a similar issue. I've searched all afternoon to find a way to reuse an ECS cluster in another CDK App than the one where the cluster was created. Referencing an existing ECS cluster requires (among other things):

  • VPC: I can export the id of the VPC when that VPC is created, but I cannot retrieve the that id using Fn.importValue due to this bug
  • Security Groups: I cannot even export the security group ids when creating the cluster using the following code:
cluster = ecs.Cluster(self, "ECSCluster", cluster_name='my-cluster', vpc=self.vpc)
security_group_ids = [sg.security_group_id for sg in cluster.connections.security_groups]
CfnOutput(self, "SGExport", value=Fn.join(',', security_group_ids), export_name='sg-ids')

Because it gives me this error: Error: FnJoin requires at least one value to be provided

Apparently cluster.connections.security_groups is empty?

@vgribok
Copy link

vgribok commented Apr 8, 2021

Same applies to EKS Cluster.fromClusterAttributes().
All the API seems to need is account, region and cluster name, as in "aws eks describe-cluster --name <cluster name>"

@mimozell
Copy link
Author

mimozell commented Apr 9, 2021

I have a feeling they are making some really strange design decisions with cdk :( Not only do they go against expectations and logic (a unique ID should be enough to give you the object, such as the cluster), but also against what we are used to with the cli and sdk...

@teuber789
Copy link

Any update on this? Still facing this problem today.

My situation is similar to @dandydev 's; I'm trying to reuse an ECS cluster in another CDK app.

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests

8 participants