使用 CDK 创建不带 NAT 网关的 AWS RDS 实例

Create an AWS RDS instance without NAT Gateway using CDK

是否可以创建 serverless RDS cluster via CDK without NAT Gateway? The NAT Gateway base charge is pretty expensive for a development environment. I'm also not interested in setting up a NAT instance. I'm attaching a Lambda in the VPC with the RDS instance like this.

    // VPC
    const vpc = new ec2.Vpc(this, 'MyVPC');

    // RDS
    const dbCluster = new rds.ServerlessCluster(this, 'MyAuroraCluster', {
      engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
      defaultDatabaseName: 'DbName',
      vpc,
    });

无服务器集群不能放入 public 子网。

这是 RDS Serverless 的硬性记录限制。

是的,你可以。您可能必须添加一些 VPC 端点(如 Secrets Manager)才能完成密码轮换,但这是可能的。您将需要创建一个包含没有 NAT 网关的子网的 VPC。

// VPC
const vpc = new ec2.Vpc(this, 'MyVPC', {
  natGateways: 0,
  subnetConfiguration: [
    {
      cidrMask: 24,
      name: 'public',
      subnetType: ec2.SubnetType.PUBLIC,
    },
    {
      cidrMask: 28,
      name: 'rds',
      subnetType: ec2.SubnetType.ISOLATED,
    }
  ]
});

// RDS
const dbCluster = new rds.ServerlessCluster(this, 'MyAuroraCluster', {
  engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
  defaultDatabaseName: 'DbName',
  vpcSubnets: {
    subnetType: ec2.SubnetType.ISOLATED,
  },
  vpc,
});

如果您想要 Secrets Manager 控制密码,请使用:

vpc.addInterfaceEndpoint('SecretsManagerEndpoint', {
  service: ec2.InterfaceVpcEndpointAwsService.SECRETS_MANAGER,
});

dbCluster.addRotationSingleUser();