Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rds: DatabaseInstanceFromSnapshot doesn't expose DBClusterSnapshotIdentifier #33889

Open
1 task
BwL1289 opened this issue Mar 24, 2025 · 1 comment · May be fixed by #33982
Open
1 task

rds: DatabaseInstanceFromSnapshot doesn't expose DBClusterSnapshotIdentifier #33889

BwL1289 opened this issue Mar 24, 2025 · 1 comment · May be fixed by #33982
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@BwL1289
Copy link

BwL1289 commented Mar 24, 2025

Describe the bug

The DatabaseInstanceFromSnapshot doesn't expose the DBClusterSnapshotIdentifier attribute so without a workaround, you can't create a db instance from a cluster snapshot.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

DBClusterSnapshotIdentifier to be exposed via DatabaseInstanceFromSnapshot for example:

dev_db_instance = rds.DatabaseInstanceFromSnapshot(
            self,
            "DatabaseInstanceFromSnapshot",
            cluster_snapshot_identifier="cluster-snapshot-id",
            vpc=vpc,
            parameter_group=parameter_group,
            engine=rds.DatabaseInstanceEngine.mysql(version=self.engine_vsn),
            subnet_group=subnet_group,
            vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
            storage_type=rds.StorageType.GP2,
            auto_minor_version_upgrade=True,
            security_groups=[security_group],
            option_group=option_group,
        )

Current Behavior

Only the snapshot_identifier is exposed.

Reproduction Steps

Try to create an rds.DatabaseInstanceFromSnapshot with a cluster snapshot id.

Possible Solution

No response

Additional Information/Context

The workaround is the following:

from typing import cast

dev_db_instance = rds.DatabaseInstanceFromSnapshot(...)

cfn_db = cast(rds.CfnDBInstance, dev_db_instance.node.default_child)
cfn_db.db_cluster_snapshot_identifier = snapshot_identifier
cfn_db.db_snapshot_identifier = None

CDK CLI Version

2.180.0

Framework Version

No response

Node.js Version

v22.12.0

OS

MacOS

Language

Python

Language Version

No response

Other information

No response

@BwL1289 BwL1289 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 24, 2025
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Mar 24, 2025
@pahud pahud self-assigned this Mar 24, 2025
@pahud
Copy link
Contributor

pahud commented Mar 24, 2025

Thanks for the report.

Solution approach:

To properly fix this issue, we would need to:

  1. Update the DatabaseInstanceFromSnapshotProps interface to add a new optional property clusterSnapshotIdentifier
  2. Modify the DatabaseInstanceFromSnapshot class to handle this property and pass it to the underlying CfnDBInstance
  3. Add validation to ensure that users don't specify both snapshotIdentifier and clusterSnapshotIdentifier at the same time
  4. Update any relevant documentation

Python Workaround:

from typing import cast

# Create your DB instance from snapshot as usual
dev_db_instance = rds.DatabaseInstanceFromSnapshot(
    self,
    "DatabaseInstanceFromSnapshot",
    vpc=vpc,
    parameter_group=parameter_group,
    engine=rds.DatabaseInstanceEngine.mysql(version=self.engine_vsn),
    subnet_group=subnet_group,
    vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC),
    storage_type=rds.StorageType.GP2,
    auto_minor_version_upgrade=True,
    security_groups=[security_group],
    option_group=option_group,
    # Note: we don't use snapshotIdentifier here as we'll override it
)

# Cast to the L1 construct (CfnDBInstance) and modify properties directly
cfn_db = cast(rds.CfnDBInstance, dev_db_instance.node.default_child)
cfn_db.db_cluster_snapshot_identifier = "cluster-snapshot-id"  # Your cluster snapshot ID here
cfn_db.db_snapshot_identifier = None  # Clear the regular snapshot identifier

TypeScript Workaround:

// Create your DB instance from snapshot as usual
const devDbInstance = new rds.DatabaseInstanceFromSnapshot(this, 'DatabaseInstanceFromSnapshot', {
  vpc,
  parameterGroup,
  engine: rds.DatabaseInstanceEngine.mysql({version: engineVsn}),
  subnetGroup,
  vpcSubnets: {subnetType: ec2.SubnetType.PUBLIC},
  storageType: rds.StorageType.GP2,
  autoMinorVersionUpgrade: true,
  securityGroups: [securityGroup],
  optionGroup,
  // Note: we don't use snapshotIdentifier here as we'll override it
});

// Get the L1 construct (CfnDBInstance) and modify properties directly
const cfnDb = devDbInstance.node.defaultChild as rds.CfnDBInstance;
cfnDb.dbClusterSnapshotIdentifier = "cluster-snapshot-id"; // Your cluster snapshot ID here
cfnDb.dbSnapshotIdentifier = undefined; // Clear the regular snapshot identifier

Making this a p2 and we welcome PRs.

@pahud pahud added p2 effort/medium Medium work item – several days of effort labels Mar 24, 2025
@pahud pahud removed their assignment Mar 24, 2025
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants