Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CDK: Is there a way to create database schema using CDK?

I have created a RDS Aurora Postgres Database Cluster and Database Instance through CDK (using java as a language). Now I am trying to achieve creating a database schema through CDK. I tried but did not find any documentation or help anywhere which tells

  1. If at all it is possible to create DB schema through CDK for RDS databases?
  2. If so, how?
  3. If not, what are the best practices for this to achieve?

If anyone has already done it or has knowledge, I will appreciate pointing me to right direction.

Thanks, Horizon7

like image 293
horizon7 Avatar asked Jun 16 '20 12:06

horizon7


1 Answers

The CDK itself does not have an out of the box solution for creating SQL schemas as it is used for managing the provisioning of infrastructure.

However, there is a tool for creating additional processes, this tool is a CustomResource.

A CustomResource will allow you to invoke a Lambda function, this function could be developed to perform SQL interaction with the RDS instance and then create the schemas.

If you enable RDS Proxy your Lambda function should be able to interact with the RDS instance without any additional considerations for networking. As long as it has the IAM permissions it can invoke the commands.

like image 190
Chris Williams Avatar answered Oct 31 '22 03:10

Chris Williams