VpcNetwork.importFromContext throws Cannot read property 'VpnGatewayId' of undefined
See original GitHub issueVersions
❯ cdk --version
0.25.2 (build 558d81f)
❯ cat package.json | grep aws-cdk
"aws-cdk": "^0.25.2"
"@aws-cdk/aws-ec2": "^0.25.2",
"@aws-cdk/aws-ecs": "^0.25.2",
"@aws-cdk/cdk": "^0.25.2",
Problem Description
I have a very standard public/private VPC deployed (it was previously deployed with CDK).
I’m trying to import that VPC from a new CDK project, like so:
const vpc = ec2.VpcNetwork.importFromContext(this, 'VPC', {
vpcName: 'Production/VPC'
})
When running cdk synth
or cdk diff
, an error is shown:
❯ cdk synth
Cannot read property 'VpnGatewayId' of undefined
I suspect this is related to #1899 that was merged 8 days ago. Related: #1523 (see comment by @brad-jones)
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Package Diff: @aws-cdk/aws-ec2 @ 0.31.0 .. 0.32.0
VpcNetwork.importFromContext(stack, 'VPC', {\n // This imports the default VPC but you can also\n // specify a 'vpcName' or 'tags'.
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
Problem lies here: packages/aws-cdk/lib/context-providers/vpcs.ts#L88
If there are no VpnGateways, the DescribeVpnGateways SDK call will return an empty array like so:
The ternary operator above should check array size, rather than whether it’s defined/null.
We will do a release next week. If you don’t want to wait for that, you can check out the repository and do a local build. Be aware, you will need a Linux or mac otherwise the build is going to give you a lot of trouble.