amazon-web-services - 如何在 CDK 中制作 Aurora Serverless 数据库
问题描述
我正在尝试制作一个极光无服务器数据库。在控制台中它很简单,我只使用默认子网组,一切都很好。
但是,当我使用 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
});
推荐阅读
- javascript - 避免对象的排序顺序 JavaScript
- python - 如何创建一个新的DataFrame,其中每一列代表一个实例在前一个DataFrame的一行中的出现
- python-3.x - 如何使用 discord.py rewrite 编辑角色权限?
- prestashop-1.7 - 修改 product-list.tpl - Prestashop 1.7.6
- linux - 如何在 GNAT CE 2019 中查询 PostgreSQL
- r - 通过它们的基础整数访问因子,而不是它们在 R 中的级别
- c - 使用提供的可变参数调用 C 回调函数会产生奇怪的结果
- javascript - 如果使用赛普拉斯的 DOM 中不存在该元素,如何处理错误
- amazon-s3 - 在 S3 存储桶中托管 Blazor WASM
- linux - 在 Linux 中按一个用户的最大大小和最后修改日期列出文件大小