- Newest
- Most votes
- Most comments
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:
-
Use the AWS CLI, SDK, or RDS API to create the database after the CDK deployment.
-
If you're using Aurora Serverless v1, you could use the Data API (if enabled) to execute SQL commands to create the database.
-
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.
-
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
