Skip to content

New RDS Database from name after ServerlessCluster.fromServerlessClusterAttributes

0

Inside my CDK I have the option to import a database instance and also to create a new one. With the new one, I can create a database with defaultDatabaseName. But how can I let the rds cluster create a new database when imported from ServerlessCluster.fromServerlessClusterAttributes?

asked 2 years ago135 views

1 Answer
0

When importing an existing RDS ServerlessCluster using ServerlessCluster.fromServerlessClusterAttributes, you cannot directly create a new database as part of that import process. The fromServerlessClusterAttributes method is designed to reference an existing cluster, not to modify it or create new databases within it.

If you need to create a new database in an imported cluster, you would typically need to do this outside of the CDK deployment process. You have a few options:

  1. Use the AWS CLI, SDK, or RDS API to create the database after the CDK deployment.

  2. If you're using Aurora Serverless v1, you could use the Data API (if enabled) to execute SQL commands to create the database.

  3. For Aurora Serverless v2 or other RDS engines, you might need to connect to the database using a standard database client and execute the CREATE DATABASE command.

  4. In some cases, you might be able to use a custom resource in your CDK stack to execute the database creation as part of your deployment, but this would require additional setup and consideration of security implications.

It's important to note that when you import an existing resource using methods like fromServerlessClusterAttributes, you're essentially telling CDK that this resource already exists and should not be managed or modified by the stack. This is why you can't directly create new databases as part of the import process.

If you frequently need to create new databases in existing clusters, you might want to consider setting up a separate process or automation for this task, rather than trying to incorporate it into your CDK infrastructure code.
Sources
interface DatabaseClusterAttributes · AWS CDK
interface IServerlessCluster · AWS CDK

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.