使用 CDK 使用 Postgresql 创建 Aurora 集群

Creating Aurora Cluster with Postgresql with CDK

运行 CDK with db-stack 包含:

    this.cluster = new DatabaseCluster(this, 'ProductDatabase', {
      defaultDatabaseName: 'ProductDb',
      engine: DatabaseClusterEngine.AURORA_POSTGRESQL,
      engineVersion: '11.4',
      masterUser: {
        username: 'clusteradmin',
      },
      instanceProps: {
        instanceType: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.SMALL),
        vpcSubnets: {
          subnetType: SubnetType.ISOLATED,
        },
        vpc: props.vpc,
      },
      parameterGroup: ParameterGroup.fromParameterGroupName(this, 'ParameterGroup', 'default.aurora-postgresql11'),
    })

失败并显示错误消息:

RDS does not support creating a DB instance with the following combination: DBInstanceClass=db.t2.small, Engine=aurora-postgresql, EngineVersion=11.4, LicenseModel=postgresql-license. For supported combinations of instance class and database engine version, see the documentation. (Service: AmazonRDS; Status Code: 400; Error Code: InvalidParameterCombination; Request ID: dfb07895-5687-486e-a39e-49b0e59a170f)

根据我从 AWS 文档中找到的信息,支持 11.4 并且所有 Postgreqsql 版本都允许 db.t2.small。命令行 aws rds describe-db-engine-versions --engine=aurora-postgresql 也包括:

       {
            "Engine": "aurora-postgresql",
            "EngineVersion": "11.4",
            "DBParameterGroupFamily": "aurora-postgresql11",
            "DBEngineDescription": "Aurora (PostgreSQL)",
            "DBEngineVersionDescription": "Aurora PostgreSQL (Compatible with PostgreSQL 11.4)",
            "ValidUpgradeTarget": [],
            "ExportableLogTypes": [
                "postgresql"
            ],
            "SupportsLogExportsToCloudwatchLogs": true,
            "SupportsReadReplica": false,
            "SupportedEngineModes": [
                "provisioned"
            ],
            "SupportedFeatureNames": [
                "s3Import"
            ],
            "Status": "available"
        }

根据 this,从 t 型(突发)实例,Aurora Postgresql 仅支持 t3.medium。所以这一行修正了定义:

instanceType: InstanceType.of(InstanceClass.BURSTABLE3, InstanceSize.MEDIUM),