如何引用 AWS CDK 中的现有 VPC 终端节点?

Seb*_*ebS 5 amazon-web-services aws-cdk

如何查找并引用堆栈中的现有 VPC 终端节点,以便将其传递给 API Gateway RestApi() 以获取私有 API?

Seb*_*ebS 7

msshenke 的答案返回 Ivpc 我需要的是 vpc 端点引用。

这就是我发现的

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-属性

需要提供现有的 vpce id 和安全组。

CDK v1

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

CDK v2

securityGroups属性可选

const ivpc  = ec2.InterfaceVpcEndpoint.fromInterfaceVpcEndpointAttributes(this, `vpceLookup`, {
  vpcEndpointId : `vpce-abcdefgh123456789`,
  port          : 443
});
Run Code Online (Sandbox Code Playgroud)