如何使用 CDK 将 AWS ECS (ApplicationLoadBalancedFargateService) 私有 IP 连接到 RDS 安全组

YuJ*_*oon 6 amazon-web-services amazon-ecs typescript aws-cdk

如何使用CDK将ECS私网IP接入RDS安全组?

我需要ApplicationLoadBalancedFargateService(CDK代码)的私有IP。

我尝试了以下方法(未能解决):

    const auroraSecurityGroup = new ec2.SecurityGroup(this, 'security-group', {
      vpc,
      allowAllOutbound: true,
      description: 'Security Group of Aurora PostgreSQL',
      securityGroupName: AURORA_SECURITY_GROUP_NAME
    });

    auroraSecurityGroup.addIngressRule(ec2.Peer.ipv4('my ecs private ip'), ec2.Port.tcp(DB_PORT), 'describe');
Run Code Online (Sandbox Code Playgroud)

Aru*_*han 3

如果你想允许特定的IP地址,你必须用cidr指定。

ec2.Peer.ipv4('1.2.3.4/32')
Run Code Online (Sandbox Code Playgroud)

允许fargate服务的安全组作为arurora seucirty组的源:

auroraSecurityGroup.connections.allowFrom(ecsService.service, Port.tcp(3306), 'Inbound');
Run Code Online (Sandbox Code Playgroud)

在本例中,假设 ecs 服务定义如下。

const service = new ecs.FargateService(this, 'Service', {
  cluster,
  taskDefinition,
  desiredCount: 5,
});
Run Code Online (Sandbox Code Playgroud)