Skip to content

feat(rds): instance engine lifecycle support #34719

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

phuhung273
Copy link
Contributor

Issue # (if applicable)

Closes #34492

Reason for this change

Cluster has this param but Instance doesn't

Description of changes

  • Instance engine lifecycle support
  • Move enum EngineLifecycleSupport to props as it is shared across cluster and instance

Describe any new or updated permissions being added

Description of how you validated changes

Unit + Integ

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team June 14, 2025 05:00
@github-actions github-actions bot added star-contributor [Pilot] contributed between 25-49 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Jun 14, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 14, 2025
Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. There are almost no problems, but I left a few very minor comments.


// For simplicity, get a public snapshot
new rds.DatabaseInstanceFromSnapshot(stack, 'FromSnapshot', {
snapshotIdentifier: 'arn:aws:rds:us-east-1:484907511898:snapshot:vuln-test-db-snapshot-prod',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this account ID not AWS official's but yours? In my opinion, tests shouldn't depend on your or someone's account with hard coding.

I know that the way has already used in integ.instance-from-cluster-snapshot.ts, but there is a possibility that the account or the snapshot will be deleted, then developers who run this test will be confused. (Furthermore, although an AWS account ID is not confidential information, it would be good not to disclosed carelessly.)

How about using environment variables or any variables (such as process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT, stack.account, etc.)?
And it would be better to write a comment to need to create the resource and the snapshot manually before running the test. (Alternatively, we may also create them in preDeploy of hooks in IntegTest and delete them in postDestroy, but it may take a long time and be difficult.)

Or, we could create a custom resource and create a snapshot of sourceInstance within it and return that. But it might be a flaky test so it might be good the first choice.

What do you think?

*Even if this approach is continued, it would be good to add some comments about what this ID refers to and how developers should handle it (whether it is okay to use as is).

Copy link
Contributor Author

@phuhung273 phuhung273 Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. To explain, I don't even know whose snapshot is that. We can find that in RDS console > Snapshot > Public and grab which ever compatible with our setting.

I was doing the same for integ.instance-from-cluster-snapshot.ts, and now that snapshot has been deleted. Agree that this should be improved for future reader.

Also really appreciate your sharing on preDeploy and hooks, will definitely try it out for simpler test.

Detail comment on how to get the snapshot ID added.

Copy link
Contributor

@go-to-k go-to-k Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. Confirmed it.

/*
 * For simplicity, this integration test uses a public snapshot.
 * By the time you rerun, the snapshot might already be deleted.
 *
 * How to get another compatible public snapshot:
 * * aws rds describe-db-snapshots --include-public --snapshot-type public --query "DBSnapshots[?Engine=='mysql' && EngineVersion=='8.0.40']" --output table
 *
 * Or find one in AWS Console > RDS > Snapshots > Public
 */

However, as far as I can see, there are currently only four snapshots of the relevant engine in public. Furthermore, it is unclear who left them there and for what purpose. In other words, there is a possibility that there will be none when executing this integ in future.

In addition, if the snapshot referenced in the test is deleted and a new snapshot ID is specified, the instance will be replaced with the new one. Then it will cause a destructive change in the integ test. Also, if the original snapshot does not exist, an error will occur when creating a stack with the existing snapshot, causing the test to fail unless you specify --disable-update-workflow or stackUpdateWorkflow: false. Anyway, Tests should be as stable as possible.

https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-rds-dbinstance.html#cfn-rds-dbinstance-dbsnapshotidentifier

If you specify a property that is different from the previous snapshot restore property, a new DB instance is restored from the specified DBSnapshotIdentifier property, and the original DB instance is deleted.

Therefore, I prefer the following approaches. How about trying different approaches?

How about using environment variables or any variables (such as process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT, stack.account, etc.)?
And it would be better to write a comment to need to create the resource and the snapshot manually before running the test. (Alternatively, we may also create them in preDeploy of hooks in IntegTest and delete them in postDestroy, but it may take a long time and be difficult.)

Or, we could create a custom resource and create a snapshot of sourceInstance within it and return that. But it might be a flaky test so it might be good the first choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found an existing implementation of another integ, so I made it general for any later work requiring snapshot.

Also tried to do the same for integ.instance-from-cluster-snapshot, but the problem is DB instance can only be restored from a MultiAZ DB cluster - which is currently not yet supported by L2 construct as L2 DBCluster only support Aurora. It is still possible with L1 and some modifications on the Snapshoter. Please let me know if you want me to do so.

Copy link
Contributor

@go-to-k go-to-k Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then, let's revert the current change in packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-from-cluster-snapshot.ts. That change could be considered separately from this PR.

Copy link
Contributor Author

@phuhung273 phuhung273 Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure thanks for understanding, integ.instance-from-cluster-snapshot reverted

*
* @default undefined - AWS RDS default setting is `EngineLifecycleSupport.OPEN_SOURCE_RDS_EXTENDED_SUPPORT`
*/
readonly engineLifecycleSupport?: EngineLifecycleSupport;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This setting applies only to RDS for MySQL and RDS for PostgreSQL.

It would be good to write it in description or validate it if possible.

https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-rds-dbinstance.html#cfn-rds-dbinstance-enginelifecyclesupport

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this, engine validation added.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 16, 2025
@@ -1079,6 +1090,11 @@ abstract class DatabaseInstanceSource extends DatabaseInstanceNew implements IDa
this.engine = props.engine;

const engineType = props.engine.engineType;

if (props.engineLifecycleSupport && !['mysql', 'postgres'].includes(engineType)) {
throw new ValidationError(`Engine '${engineType}' does not support engine lifecycle support`, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more helpful.

Suggested change
throw new ValidationError(`Engine '${engineType}' does not support engine lifecycle support`, this);
throw new ValidationError(`'engineLifecycleSupport' can only be specified for RDS for MySQL and RDS for PostgreSQL, got: '${engineType}'`, this);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this is updated

@@ -1492,6 +1508,10 @@ export class DatabaseInstanceReadReplica extends DatabaseInstanceNew implements
throw new ValidationError(`Cannot set 'backupRetention', as engine '${engineDescription(props.sourceDatabaseInstance.engine)}' does not support automatic backups for read replicas`, this);
}

if (props.sourceDatabaseInstance.engine?.engineType && props.engineLifecycleSupport && !['mysql', 'postgres'].includes(props.sourceDatabaseInstance.engine.engineType)) {
throw new ValidationError(`Engine '${props.sourceDatabaseInstance.engine.engineType}' does not support engine lifecycle support`, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this is updated

@phuhung273 phuhung273 requested a review from go-to-k June 17, 2025 16:25
Comment on lines +1511 to +1515
const engineType = props.sourceDatabaseInstance.engine?.engineType;
if (engineType && props.engineLifecycleSupport && !['mysql', 'postgres'].includes(engineType)) {
throw new ValidationError(`'engineLifecycleSupport' can only be specified for RDS for MySQL and RDS for PostgreSQL, got: '${engineType}'`, this);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please change the following together?

    const instance = new CfnDBInstance(this, 'Resource', {
      // ...
      // ...
-     engine: shouldPassEngine ? props.sourceDatabaseInstance.engine?.engineType : undefined,
+     engine: shouldPassEngine ? engineType : undefined,
      // ...
      // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure this is updated


// For simplicity, get a public snapshot
new rds.DatabaseInstanceFromSnapshot(stack, 'FromSnapshot', {
snapshotIdentifier: 'arn:aws:rds:us-east-1:484907511898:snapshot:vuln-test-db-snapshot-prod',
Copy link
Contributor

@go-to-k go-to-k Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then, let's revert the current change in packages/@aws-cdk-testing/framework-integ/test/aws-rds/test/integ.instance-from-cluster-snapshot.ts. That change could be considered separately from this PR.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 9bf5663
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@go-to-k go-to-k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Approved!

@phuhung273
Copy link
Contributor Author

Thanks for your review @go-to-k 💯

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-rds: Add support for engineLifecycleSupport configuration in L2/L3 constructs for RDS Instances
3 participants