4

How can I lookup and reference an existing VPC Endpoint in my Stack so that I can pass it to API Gateway RestApi() for private API?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
SebS
  • 571
  • 3
  • 6
  • 16

2 Answers2

7

msshenke's answer returns Ivpc what I needed was vpc endpoint reference.

This is what I found

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.InterfaceVpcEndpoint.html#static-from-wbr-interface-wbr-vpc-wbr-endpoint-wbr-attributesscope-id-attrs

Need to supply the existing vpce id and the security group.

CDK v1

const ivpc = Vpc.InterfaceVpcEndpoint.fromInterfaceVpcEndpointAttributes(this, "VPC", {
    port: 443,
    vpcEndpointId: "vpce-1234567890",
    securityGroups: ["https-sg"] // or whatever you are using
});

CDK v2

securityGroups property optional

const ivpc  = ec2.InterfaceVpcEndpoint.fromInterfaceVpcEndpointAttributes(this, `vpceLookup`, {
  vpcEndpointId : `vpce-abcdefgh123456789`,
  port          : 443
});
fusion27
  • 2,396
  • 1
  • 25
  • 25
SebS
  • 571
  • 3
  • 6
  • 16
-2

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.Vpc.html#static-from-wbr-vpc-wbr-attributesscope-id-attrs

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.VpcAttributes.html

You'd need to have the vpc id and availability zones your subnets are using at a minimum.

const vpc = Vpc.fromVpcAttributes(this, "VPC", {
    vpcId: "vpc-1234567890",
    availabilityZones: ["us-east-1a", "us-east-1b"] // or whatever you are using
});