(aws-ecs): fromClusterAttributes requires VPC
See original GitHub issueI’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:
- Created 3 years ago
- Reactions:4
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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…
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.