如何在 CDK (AWS) 中将安全组添加到 VPC 端点

How to add security group to VPC Endpoint in CDK (AWS)

我的 AWS 账户上已有一个 VPC 终端节点。当我部署我的 CDK 堆栈时,我需要以某种方式向该 VPC 端点添加一个安全组,以便我的服务器能够与另一个网络上的 Redshift 集群通信。

我这样定义我的安全组:

const securityGroup = new ec2.SecurityGroup(this, "SecurityGroup", {
        vpc,
        allowAllOutbound: true,
    });

如何将该安全组添加到 VPC 端点?我知道端点 ID,但不知何故无法弄清楚如何执行此操作。我尝试通过 ID 获取 VPC 端点并尝试使用安全组

您需要使用 ec2.InterfaceVpcEndpoint which creates a new Vpc Endpoint and allows for you to add in security groups ids. Borrowing from here 它可能如下所示:

    ec2.InterfaceVpcEndpoint(
        self,
        "VPCe - Redshift",
        service=ec2.InterfaceVpcEndpointService("redshift.amazonaws.com")
        ),
        private_dns_enabled=True,
        vpc=self.vpc,
        security_groups=[securityGroup],
    )