aws-cdk: Cannot refer to subnet by name for imported VPC
Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository’s issues are intended for feature requests and bug reports.
-
I’m submitting a …
- 🪲 bug report
- 🚀 feature request
- 📚 construct library gap
- ☎️ security issue or vulnerability => Please see policy
- ❓ support request => Please see note at the top of this template.
-
What is the current behavior? If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce Please describe/document how to deploy an L2 construct that has vpc_subnets argument of SubnetSelection type.
Documentation mentions: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ec2/SubnetSelection.html subnet_name, but it is unclear what it really is. Subnet (neither Cfn nor L2 construct ) does not have a subnet_name property.
I wasnt able to make it work, always getting
jsii.errors.JSIIError: There are no subnets named 'xxxx' in this VPC. Use a different VPC subnet selection.
Example code piece:
vpc = aws_ec2.Vpc.from_lookup(
scope=self,
id='dev-eks-vpc',
is_default=False,
tags={
'aws:cloudformation:stack-name':'dev-eks-vpc'
}
)
eks_cluster = aws_eks.Cluster(
scope=self,
id='EksCluster',
vpc=vpc,
vpc_subnets=[aws_ec2.SubnetSelection(subnet_type=aws_ec2.SubnetType.PRIVATE)],
cluster_name='EksCluster-dev',
version='1.12'
)
eks_autoscaling_group = eks_cluster.add_capacity(
id='EksClusterAsg',
instance_type='m5.large',
desired_capacity=2,
vpc_subnets=aws_ec2.SubnetSelection(subnet_name='dev-eks-vpc/DevEksVpc/PrivateSubnet2')
)
for subnet_name I tried what’s under Name tag, logical id and physical id. None works
-
What is the expected behavior (or behavior of feature suggested)? Document how to deploy resources in certain subnets.
-
What is the motivation / use case for changing the behavior or adding this feature? It’s quite clear users want to have an abiility to control where are the resources deployed.
-
Please tell us about your environment:
- CDK CLI Version: 1.3.0
- Module Version: 1.3.0
- OS: [all]
- Language: [all]
-
Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc) https://github.com/aws/aws-cdk/issues/2393 https://github.com/aws/aws-cdk/issues/1577
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 15 (6 by maintainers)
Commits related to this issue
- fix(ec2): fix subnet selection on looked-up VPCs Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is likely to ... — committed to aws/aws-cdk by rix0rrr 5 years ago
- fix(ec2): fix subnet selection on looked-up VPCs (#4090) Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is ... — committed to aws/aws-cdk by rix0rrr 5 years ago
- fix(ec2): fix subnet selection on looked-up VPCs (#4090) Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is ... — committed to aws/aws-cdk by rix0rrr 5 years ago
Trying to decipher why this is closed - alternatives to lookup by subnet name are suggested (look up by group name, look up by subnet id), but it’s still not possible that I can see to refer to a subnet by name, which was the original issue.
Use case: trying to use CDK with non-CDK managed subnets that have no tagging, but have predictable name formats.
Me and author of the issue are struggling with the same issue so I have debugged it and here are my findings: I guess there is a bug in CDK that prevents from correctly receiving information of imported vpc when only subnet name is selected in SubnetSelection. This is possibly caused by missing privateSubnetNames and publicSubnetNames in DUMMY_VPC_PROPS : https://github.com/aws/aws-cdk/blob/3ba14c8c91dfe887db2469b983e71de5c3460c43/packages/%40aws-cdk/aws-ec2/lib/vpc.ts#L1410-L1422 So the CDK CLI doesn’t try to fetch the missing context ( subnet names ) and just stop with an error after first run-through.