微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 CDK 中制作 Aurora Serverless 数据库

如何解决如何在 CDK 中制作 Aurora Serverless 数据库

我正在尝试制作一个 aurora 无服务器数据库。在控制台中,它很简单,我只使用认子网组,一切都很好。

但是,当我使用 cdk 时,我收到错误消息“aurora Serverless 不支持子网位于同一可用区中的数据库子网组。选择子网位于不同可用区中的数据库子网组。”。我试图排除故障,但我真的不明白为什么它会失败,我猜它使用与我手动执行时相同的认子网(并且可以正常工作)?那为什么用cdk突然就全错了...

const auroraDatabaseCluster = new rds.ServerlessCluster(this,'Database',{
    engine: rds.DatabaseClusterEngine.aurora_POSTGREsql,credentials: rds.Credentials.fromSecret(masterSecret),parameterGroup: clusterParameterGroup,defaultDatabaseName: databaseName,vpc: vpc,securityGroups: [databaseSecurityGroup],storageEncryptionKey: databaseKey,deletionProtection: false
  });

有人知道哪里出了问题吗?

我也可以使用区域极光数据库让它工作......

const auroraDatabaseCluster = new rds.DatabaseCluster(this,{
    engine: rds.DatabaseClusterEngine.auroraPostgres({version: rds.auroraPostgresEngineVersion.VER_11_8}),instances: 2,// Todo should be 2
    credentials: rds.Credentials.fromSecret(masterSecret),port: endpointPort,storageEncrypted: true,deletionProtection: false,// Todo enable in prod
    parameterGroup: clusterParameterGroup,instanceProps: {
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3,ec2.InstanceSize.MEDIUM),vpcsubnets: {
        subnetType: ec2.subnetType.PRIVATE,},vpc,});

解决方法

我通过使用 onePerAZ=true 手动添加数据库安全组解决了该问题

const subnetGroup = new rds.SubnetGroup(this,"subnetGroup",{
        description: `Subnetgroup for serverless postgres aurora databasa`,vpc: vpc,vpcSubnets: {onePerAz: true},})

  const auroraDatabaseCluster = new rds.ServerlessCluster(this,'Database',{
    engine: rds.DatabaseClusterEngine.AURORA_POSTGRESQL,credentials: rds.Credentials.fromSecret(masterSecret),parameterGroup: clusterParameterGroup,defaultDatabaseName: databaseName,subnetGroup: subnetGroup,securityGroups: [databaseSecurityGroup],storageEncryptionKey: databaseKey,deletionProtection: false
  });

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。