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.

@aws-cdk/aws-ec2.InterfaceVpcEndpoint Fails Test

See original GitHub issue

Reproduction Steps

Run the jest test below:

import { InterfaceVpcEndpoint, InterfaceVpcEndpointAwsService, Vpc }
  from "@aws-cdk/aws-ec2";
import { Stack } from "@aws-cdk/core";

test("InterfaceVpcEndpoint", () => {
  // given
  const stack = new Stack();
  const vpc = new Vpc(stack, "TestVpc");
  // when
  new InterfaceVpcEndpoint(stack, "TestEndpoint", {
    lookupSupportedAzs: true,
    service: InterfaceVpcEndpointAwsService.SECRETS_MANAGER,
    vpc: vpc,
  });
});

What did you expect to happen?

The test to succeed.

What actually happened?

The test failed with the error Cannot look up VPC endpoint availability zones if account/region are not specified and stack trace:

at InterfaceVpcEndpoint.validateCanLookupSupportedAzs (node_modules/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts:556:13)
      at InterfaceVpcEndpoint.endpointSubnets (node_modules/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts:526:10)
      at new InterfaceVpcEndpoint (node_modules/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts:480:28)
      at Object.<anonymous> (test/cdk-constructs/interface-vpc-endpoint.test.ts:10:3)

Environment

  • CDK CLI Version : 1.103.0 (build bc13a66)
  • Framework Version: 1.103.0
  • Node.js Version: v14.15.1
  • OS : Ubuntu 20.04.2 LTS
  • Language (Version): TypeScript 4.2.4
  • Jest (Version) : 26.6.3
  • ts-jest (version): 26.5.6

Other

I understand this can work without the lookupSupportedAzs: true, param property, but my default profile is configured. I’m unable to determine why this is failing.


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Jun 24, 2021

This test will work, even with the dummy account number

it("Should have InterfaceVpcEndpoint", () => {
  // given
  const app = new App();
  const env = { account: '123456789012', region: 'us-west-2' };
  const stack = new Vpctest.VpctestStack(app, "TestStack", {env: env});

  expectCDK(stack).to(haveResourceLike("AWS::EC2::VPCEndpoint"))
});

The code will throw the error you received on creating an InterfaceVpcEndpoint only if both account and region of the stack are undefined and lookupSupportedAzs is true. So it doesn’t actually matter what the values are for this test to pass https://github.com/aws/aws-cdk/blob/7966f8d48c4bff26beb22856d289f9d0c7e7081d/packages/%40aws-cdk/aws-ec2/lib/vpc-endpoint.ts#L546-L557

0reactions
fractionalJoecommented, Jul 18, 2021

Thanks @peterwoodworth, that solved my issue. Is this quirk of CDK_DEFAULT_ACCOUNT (and I’m assuming CDK_DEFAULT_REGION) returning undefined documented anywhere for future reference? I’m aware now but others may have similar questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot issues with Amazon VPC interface endpoints
I'm using Amazon Virtual Private Cloud (Amazon VPC) to create an interface VPC endpoint. However, I can't select my preferred subnet for the ......
Read more >
What is an Interface VPC Endpoint and how can I ... - YouTube
We appreciate your feedback: https://amazonintna.qualtrics.com/jfe/form/SV_a5xC6bFzTcMv35sFind more details in the AWS Knowledge Center: ...
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