-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Cannot refer to subnet by name for imported VPC #3650
Comments
Can you please provide a code snippet for reproduction? |
@eladb |
The subnet name is the name of group of subnets created using the Since in this case you're looking up the VPC instead of creating it, it will read the subnet names from some tags that the CDK VPC provisioner would put on it. If no names are specified or found on the subnet tags, the names will be |
You should probably select subnets by type, unless you know you have a reason to use names. |
I am having troubles to make it work though, as subnet_configuration is applied for each AZ and carries the same data. For instance:
adds aws-cdk:subnet-name = PrivateName to each private subnet. Is it possible to name subnets individually?
Following code does tag the subnets, but tags values are not respected by subnet_selection |
I also confirm that this freature does not work for imported vpc. Whatever the data original vpc object carries is lost when vpc is imported and subnet name-based selection does not work. I don't really want to go with Cfn* resources as so much work is done behind the scenes. Do you guys plan to make it work someday? |
Me and author of the issue are struggling with the same issue so I have debugged it and here are my findings: aws-cdk/packages/@aws-cdk/aws-ec2/lib/vpc.ts Lines 1410 to 1422 in 3ba14c8
So the CDK CLI doesn't try to fetch the missing context ( subnet names ) and just stop with an error after first run-through. |
You cannot pick individual subnets using the subnet selection mechanism, you just refer to subnet groups, which is a set of subnets of the same type spreading across all AZs. Apparently there is a bug for imported subnets which prevents this from working completely. We will look into this, but in the mean time the best way around this is probably to use the escape hatch mechanism. |
Could you throw some light on how to utilize the escape hatch mechs in this case? |
You will have to know the subnet IDs, and override the CloudFormation resource properties to use exactly those IDs. |
Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is likely to fail. Add an exception to make the initial lookup not fail. Fixes #3650.
Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is likely to fail. Add an exception to make the initial lookup not fail. Fixes #3650.
Looked-up VPCs are created with a dummy configuration before the first lookup happens; a `selectSubnets` call on the dummy configuration is likely to fail. Add an exception to make the initial lookup not fail. Fixes #3650.
Hello, how it's going? Sorry if I've places this message in the wrong thread, but I still not able to attach subnets to EC2 instance by using subnet selection provided by |
@Flood-ctrl did you try something like this:
I my code I imported the vpc, and when using this line of code "vpcSubnets: {subnetName: "public"}," I got an error of _"vpcId of undefined", something like that, and believe or not by executing the cdk synth using this "vpcSubnets: cdk.Fn.importValue("public")", which did bring info, but incorrect, and then running again the synth but using "vpcSubnets: {subnetName: "public"}" fixed the issue. My steps:
It's not a fix, but works, so for now... I'll stick with that. |
Is this issue fixed? I am still having the same problem when I try to import a VPC and then lookup a subnet by name. My organization has a private subnet that I can't use, so I can't just grab the private subnet Type.
However, if instead first comment out the subnet_group_name and instead use subnet type it will populate my cdk.context.json when I do a cdk synth From that point I can uncomment the group_name_lookup and remove the type lookup and the synth will complete successfully. Because I deploy this code to different regions and environments I am not able to commit my cdk.context.json to my repo. Unless there is a way to do that without breaking each time I deploy to a new env/region? |
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. |
I've spent the past few days working around this issue, and I agree that this issue should not be closed because subnet import by subnet name is not a supported action when using ISubnet.fromAttributes or SubnetSelection. Subnet groups, however, can be imported by name via SubnetSelection. The functionality to import a subnet by group name can get you what you want provided you don't actually care about subnet group names. I was able to piece together the puzzle loosely described by the importing-an-existing-vpc documentation. This is accomplished by setting a couple of tags (described below).
This example names the |
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 ...
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:
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:
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)
Cannot get subnets from a previously deployed VPC #2393
VpcPlacement: allow picking subset of subnets #1577
The text was updated successfully, but these errors were encountered: