aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.66k stars 3.92k forks source link

RDS: cannot major-version upgrade Aurora cluster with custom instance parameter group #26072

Open mjgp2 opened 1 year ago

mjgp2 commented 1 year ago

Describe the bug

In order to do an in-place major version upgrade of Aurora, you need to set dbInstanceParameterGroupName on the cluster, not just on the individual instances. You cannot do this today.

Expected Behavior

Aurora cluster would do a major version upgrade

Current Behavior

On trying to upgrade the cluster:

Error: The stack named XXXX failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "The current DB instance parameter group XXXXX is custom. You must explicitly specify a new DB instance parameter group, either default or custom, for the engine version upgrade.

Reproduction Steps

new DatabaseCluster(this, id, {
    ...
      instanceProps: {
        parameterGroup: ParameterGroup.fromParameterGroupName(this, `instance-parameter-group-15`, `${this.databaseName}-aurora15-custom-instance-parameter-group`),
      },
      parameterGroup: ParameterGroup.fromParameterGroupName(this, `cluster-parameter-group-15`, `${this.databaseName}-aurora15-custom-cluster-parameter-group`),
    });

Possible Solution

Workaround:

    const cluster: CfnDBCluster = this.cluster.node.children.filter(x => x instanceof CfnDBCluster)[0] as CfnDBCluster;
    cluster.dbInstanceParameterGroupName = `${this.databaseName}-aurora15-custom-instance-parameter-group`;

Additional Information/Context

No response

CDK CLI Version

2.61.1

Framework Version

No response

Node.js Version

20.1.0

OS

macos

Language

Typescript

Language Version

No response

Other information

No response

peterwoodworth commented 1 year ago

Whatever you pass in for the name in fromParameterGroupName should be getting set as the cluster.dbInstanceParameterGroupName, so I'm not sure why the escape hatch is necessary. Could you illustrate the difference in your synthesized template both with and without the escape hatch?

mjgp2 commented 1 year ago

Sure.

With:

{
   "Type": "AWS::RDS::DBCluster",
   "Properties": {
    "DatabaseName": "xxx",
    "DBClusterIdentifier": "xxx-integration",
    "DBClusterParameterGroupName": "xxx-aurora15-custom-cluster-parameter-group",
    "DBInstanceParameterGroupName": "xxx-aurora15-custom-instance-parameter-group",
    "DBSubnetGroupName": {
     "Ref": "xxxdatabaseSubnets48D94137"
    },
    ...
   },
   ...
}

Without:

{
   "Type": "AWS::RDS::DBCluster",
   "Properties": {
    "DatabaseName": "xxx",
    "DBClusterIdentifier": "xxx-integration",
    "DBClusterParameterGroupName": "xxx-aurora15-custom-cluster-parameter-group",
    "DBSubnetGroupName": {
     "Ref": "xxxdatabaseSubnets48D94137"
    },
    ...
   },
   ...

Note the instance with or without the hatch has the correct group name:

{
   "Type": "AWS::RDS::DBInstance",
   "Properties": {
    "AutoMinorVersionUpgrade": false,
    "DBClusterIdentifier": {
     "Ref": "xxxdatabase01057C8A"
    },
    "DBInstanceClass": "db.t4g.medium",
    "DBInstanceIdentifier": "xxx-integrationinstance1",
    "DBParameterGroupName": "xxx-aurora15-custom-instance-parameter-group",
    "DBSubnetGroupName": {
     "Ref": "xxxdatabaseSubnets48D94137"
    },
    "EnablePerformanceInsights": true,
    "Engine": "aurora-postgresql",
    ...
  },
caveman-dick commented 2 months ago

I have just come across this issue too. I managed to fix using a slightly simpler escape-hatch:

const cfnGreenCluster = greenCluster.node.defaultChild as rds.CfnDBCluster;
cfnGreenCluster.dbInstanceParameterGroupName = "my-custom-pg";