question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-ecs): fromClusterAttributes requires VPC

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6

github_iconTop GitHub Comments

2reactions
mimozellcommented, 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…

1reaction
tscully49commented, Jan 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class Cluster (construct) · AWS CDK
A regional grouping of one or more container instances on which you can run tasks and services. Example. declare const vpc: ec2.Vpc; const...
Read more >
Cluster — AWS Cloud Development Kit 1.182.0 ...
A regional grouping of one or more container instances on which you can run tasks and services. ExampleMetadata. infused. Example: # vpc: ec2.Vpc...
Read more >
Amazon ECS interface VPC endpoints (AWS PrivateLink)
You can use a VPC endpoint to create a private connection between your VPC and Amazon ECS without requiring access over the internet...
Read more >
Set up to use Amazon ECS - Amazon Elastic Container Service
If your account supports Amazon EC2 Classic, select the VPC that you created in the previous task. Amazon ECS container instances do not...
Read more >
Set up to use Amazon ECS - AWS Documentation
Amazon Virtual Private Cloud (Amazon VPC) enables you to launch AWS resources into a virtual network that you've defined. Note. The Amazon ECS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found