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

How can I reference an existing VPC Endpoint in AWS CDK?

如何在我的堆栈中查找和引用现有的 VPC 端点,以便我可以将其传递给 API Gateway RestApi() for private API?

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

您至少需要知道您的子网正在使用的 vpc id 和可用性区域。

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

msshenke 的回答returns 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-attrs

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

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