Reputation: 100
I am trying to import and existing non-default VPC into my CDK app. I have seen a lot of questions asked regrading the VPC fromLookup and not much of solution. I am having issues where the function vpc.fromLookup returns "Could not find any VPCs matching". I have provided these filters, and the env. account and region are set as well in the stack. I just cant figure out why the VPC is not found. I have triple checked the VPC id and Name and it all exists. any help is truly appreciated as I am new to AWS and CDK.
I have also trying just using tagName or VPCId but still got the same error.
[Error at /MyStack] Could not find any VPCs matching {"account":"00000000","region":"ca-central-1","filter":{"tag:aws-cdk:subnet-type":"private","vpc-id":"vpc-00000000","tag:Name":"vpc","isDefault":"false"},"returnAsymmetricSubnets":true} Found errors
const vpc = ec2.Vpc.fromLookup(this, "VPC", { vpcName: vpcName, isDefault: false,
vpcId: vpcId, tags: { "aws-cdk:subnet-type": "private" },
});
env: {
account: process.env.CDK_DEPLOY_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEPLOY_REGION || process.env.CDK_DEFAULT_REGION,
},
Thank you in advance!
Upvotes: 1
Views: 4271
Reputation: 100
Issue is resolved. My issue was that the BastionHostLinux was set as subnetType Public and thats why I was getting error "There are no '${subnetType}' subnet groups in this VPC". which led me to think that I need to add tags to my VPC. sure enough adding the tags filter to my VPC resolved the error but then I was getting the " Could not find any VPCs matching...". So I learned – don’t rely on ERROR Messages...
Changed VPC
const vpc = ec2.Vpc.fromLookup(this, "VPC", { vpcName: vpcName, isDefault: false,
vpcId: vpcId, tags: { "aws-cdk:subnet-type": "private" }, },
to
const vpc = ec2.Vpc.fromLookup(this, "VPC", {
vpcId: vpcId,
isDefault: false,
});
and VPC is imported no problem.
Upvotes: 1