question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RDS: `DatabaseClusterFromSnapshot` should allow setting `copyTagsToSnapshot`

See original GitHub issue

Describe the bug

Today, the copyTagsToSnapshot property exists on DatabaseClusterProps not DatabaseClusterBaseProps: https://github.com/aws/aws-cdk/blob/789e8d2aaa0aefb6d17e4ebc0d56c17e9999add0/packages/%40aws-cdk/aws-rds/lib/cluster.ts#L497-L511

It’s also not set in the DatabaseClusterFromSnapshot construct, so if you switch a DatabaseCluster to DatabaseClusterFromSnapshot, you’ll get this diff:

[~] AWS::RDS::DBCluster CdkPipelinesPrototype-dev-us-east-1/Database/Database/cdk-pipeline-example-dev-Cluster DatabasecdkpipelineexampledevClusterC6927963 replace
 ├─ [-] CopyTagsToSnapshot
 │   └─ true
<trimmed>

This is especially noticeable because the value defaults to true in the L2 construct, which is different from the CloudFormation default (false): https://github.com/aws/aws-cdk/blob/789e8d2aaa0aefb6d17e4ebc0d56c17e9999add0/packages/@aws-cdk/aws-rds/lib/cluster.ts#L505-L510

Unlike other values that are explicitly unset when using DatabaseClusterFromSnapshot (e.g., KmsKeyId, MasterUsername, MasterUserPassword - see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#cfn-rds-dbcluster-kmskeyid), the docs for CopyTagsToSnapshot don’t specify that you shouldn’t set the value when restoring from a snapshot.

Expected Behavior

I expected to be able to switch from a DatabaseCluster to a DatabaseClusterFromSnapshot while retaining the same default behaviors.

Current Behavior

Currently, the CopyTagsToSnapshot value shows as being unset (which will change to the CloudFormation default of false) when changing from a DatabaseCluster to DatabaseClusterFromSnapshot.

Reproduction Steps

https://github.com/blimmer/cdk-bug-reports/compare/rds-copy-tags-to-snapshot?expand=1

In this simple stack:

import { Stack, StackProps } from 'aws-cdk-lib';
import { Vpc } from 'aws-cdk-lib/aws-ec2';
import { AuroraPostgresEngineVersion, DatabaseCluster, DatabaseClusterEngine, DatabaseClusterFromSnapshot } from 'aws-cdk-lib/aws-rds';
import { Construct } from 'constructs';

export class CdkBugReportsStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = new Vpc(this, 'VPC')
    new DatabaseCluster(this, 'DatabaseCluster', {
      engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
      instanceProps: {
        vpc
      }
    })

    new DatabaseClusterFromSnapshot(this, 'DatabaseClusterFromSnapshot', {
      snapshotIdentifier: 'arn:aws:rds:us-east-1:12345678910:cluster-snapshot:rds:example-2022-04-12-09-26',
      engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
      instanceProps: {
        vpc
      }
    })
  }
}

The resource with the id DatabaseCluster has CopyTagsToSnapshot set to true (the default in the L2 construct):

"DatabaseCluster68FC2945": {
  "Type": "AWS::RDS::DBCluster",
  "Properties": {
    "Engine": "aurora-postgresql",
    "CopyTagsToSnapshot": true,

However, the one restored from the snapshot does not have this value set:

"DatabaseClusterFromSnapshotB2BFF6A0": {
  "Type": "AWS::RDS::DBCluster",
  "Properties": {
    "Engine": "aurora-postgresql",
	// CopyTagsToSnapshot is missing

Possible Solution

I think copyTagsToSnapshot should be moved up to DatabaseClusterBaseProps and should default to true for DatabaseClusterFromSnapshot for consistency.

Additional Information/Context

You can work around this temporarily by setting the value on the L1 construct, e.g.:

const db = new DatabaseClusterFromSnapshot(this, 'DatabaseClusterFromSnapshot', {
  snapshotIdentifier: 'arn:aws:rds:us-east-1:12345678910:cluster-snapshot:rds:example-2022-04-12-09-26',
  engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_13_4 }),
  instanceProps: {
    vpc
  }
});
(db.node.defaultChild as CfnDBCluster).copyTagsToSnapshot = true;

CDK CLI Version

2.20.0

Framework Version

No response

Node.js Version

16.14.0

OS

macOS

Language

Typescript

Language Version

No response

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
AnuragMohapatracommented, Apr 15, 2022

Hi,

I would like to pick this change and help in implementing it, will open a PR with the solution soon.

Let me know in case of any concerns.

0reactions
github-actions[bot]commented, Apr 25, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class DatabaseClusterFromSnapshot (construct) · AWS CDK
You can use either the name or the Amazon Resource Name (ARN) to specify a DB cluster snapshot. However, you can use only...
Read more >
@aws-cdk/aws-rds - npm
Use DatabaseClusterFromSnapshot to create a cluster from a snapshot: ... To use the storage auto scaling option of RDS you can specify the ......
Read more >
modify-db-cluster — AWS CLI 2.9.9 Command Reference - rds
Modify the settings for an Amazon Aurora DB cluster or a Multi-AZ DB cluster. You can change one or more settings by specifying...
Read more >
awsrds - Go Packages
Amazon Relational Database Service Construct Library. import rds "github.com/aws/aws-cdk-go/awscdk". Starting a clustered database. To set up a clustered ...
Read more >
AWS CDK : snapshot restore an existing RDS Aurora ...
You can access the underlying CloudFormation resource as an L1 construct. const cluster = new rds.DatabaseCluster(this, 'Database' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found