如何在 CDK 中制作 Aurora Serverless 数据库
How to Make Aurora Serverless database in CDK
我正在尝试制作一个极光无服务器数据库。在控制台中,它很简单,我只使用默认的子网组,一切都很好。
当我使用 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, 'Database', {
engine: rds.DatabaseClusterEngine.auroraPostgres({version: rds.AuroraPostgresEngineVersion.VER_11_8}),
instances: 2, // TODO should be 2
credentials: rds.Credentials.fromSecret(masterSecret),
defaultDatabaseName: databaseName,
port: endpointPort,
storageEncrypted: true,
storageEncryptionKey: databaseKey,
deletionProtection: false, // TODO enable in prod
parameterGroup: clusterParameterGroup,
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MEDIUM),
securityGroups: [databaseSecurityGroup],
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,
vpc: vpc,
subnetGroup: subnetGroup,
securityGroups: [databaseSecurityGroup],
storageEncryptionKey: databaseKey,
deletionProtection: false
});
我正在尝试制作一个极光无服务器数据库。在控制台中,它很简单,我只使用默认的子网组,一切都很好。
当我使用 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, 'Database', {
engine: rds.DatabaseClusterEngine.auroraPostgres({version: rds.AuroraPostgresEngineVersion.VER_11_8}),
instances: 2, // TODO should be 2
credentials: rds.Credentials.fromSecret(masterSecret),
defaultDatabaseName: databaseName,
port: endpointPort,
storageEncrypted: true,
storageEncryptionKey: databaseKey,
deletionProtection: false, // TODO enable in prod
parameterGroup: clusterParameterGroup,
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MEDIUM),
securityGroups: [databaseSecurityGroup],
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,
vpc: vpc,
subnetGroup: subnetGroup,
securityGroups: [databaseSecurityGroup],
storageEncryptionKey: databaseKey,
deletionProtection: false
});