question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VpcNetwork.importFromContext throws Cannot read property 'VpnGatewayId' of undefined

See original GitHub issue

Versions

❯  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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
PaulMaddoxcommented, Mar 12, 2019

Problem lies here: packages/aws-cdk/lib/context-providers/vpcs.ts#L88

// Find attached+available VPN gateway for this VPC
const vpnGatewayResponse = await ec2.describeVpnGateways({
    Filters: [
    {
        Name: 'attachment.vpc-id',
        Values: [vpcId]
    },
    {
        Name: 'attachment.state',
        Values: ['attached']
    },
    {
        Name: 'state',
        Values: ['available']
    }
    ]
}).promise();
const vpnGatewayId = vpnGatewayResponse.VpnGateways ? vpnGatewayResponse.VpnGateways[0].VpnGatewayId : undefined;

If there are no VpnGateways, the DescribeVpnGateways SDK call will return an empty array like so:

❯  aws ec2 describe-vpn-gateways                                                                                                                  │
{                                                                                                                                                 │
    "VpnGateways": []                                                                                                                             │
}                                                                                                                                                 │

The ternary operator above should check array size, rather than whether it’s defined/null.

0reactions
rix0rrrcommented, Mar 15, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found