-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Open
Labels
@aws-cdk/aws-rdsRelated to Amazon Relational DatabaseRelated to Amazon Relational DatabasebugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2
Description
Describe the bug
When a DatabaseCluster is configured with removalPolicy: RemovalPolicy.RETAIN, the auto-created Parameter Group does not inherit this removal policy, causing CloudFormation stack deletion to fail with the error "Parameter Group is still in use by database instances."
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
Auto-created Parameter Groups should inherit the parent cluster's RemovalPolicy to ensure consistent lifecycle management.
Current Behavior
Current Behavior:
const cluster = new DatabaseCluster(this, 'MyCluster', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
writer: ClusterInstance.provisioned('writer'),
vpc,
removalPolicy: RemovalPolicy.RETAIN, // Applied to cluster
parameters: {
'shared_preload_libraries': 'pg_stat_statements'
}
});Reproduction Steps
- Create a
DatabaseClusterwithremovalPolicy: RemovalPolicy.RETAIN - Include
parametersproperty to trigger auto-creation of Parameter Group - Deploy the stack
- Attempt to delete the stack
- Observe CloudFormation error about Parameter Group still being in use
Possible Solution
Modify the Parameter Group creation in cluster.ts to inherit the cluster's removal policy:
const parameterGroup = props.parameterGroup ?? (
props.parameters
? new ParameterGroup(this, 'ParameterGroup', {
engine: props.engine,
parameters: props.parameters,
removalPolicy: props.removalPolicy, // Add this line
})
: undefined
);Additional Information/Context
Workaround
Users can work around this issue by manually creating the Parameter Group with the desired removal policy:
const parameterGroup = new ParameterGroup(this, 'MyParameterGroup', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
parameters: {
'shared_preload_libraries': 'pg_stat_statements'
},
removalPolicy: RemovalPolicy.RETAIN,
});
const cluster = new DatabaseCluster(this, 'MyCluster', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_15_4 }),
writer: ClusterInstance.provisioned('writer'),
vpc,
parameterGroup, // Use explicit parameter group
removalPolicy: RemovalPolicy.RETAIN,
});AWS CDK Library version (aws-cdk-lib)
aws-cdk-lib@2.196.1
AWS CDK CLI version
2.1021.0 (build 059c862)
Node.js Version
v22.11.0
OS
mac os x
Language
TypeScript
Language Version
No response
Other information
No response
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-rdsRelated to Amazon Relational DatabaseRelated to Amazon Relational DatabasebugThis issue is a bug.This issue is a bug.effort/mediumMedium work item – several days of effortMedium work item – several days of effortp2