I created a Postgres RDS database using the CDK. I read the documentation but didn't find a way to create tables through it.
The language I'm using is TypeScript.
I created a Postgres RDS database using the CDK. I read the documentation but didn't find a way to create tables through it.
The language I'm using is TypeScript.
You cannot create a RDS table using the CDK or CloudFormation.
You can use the AWS SDK client to execute a CREATE TABLE...
command against your database. The SDK client can be used locally or in a lambda function, for instance.
There's no AWS CDK support for this. However, I've created a package named cloudformation-sql-run that helps with that. You can use it as follows:
const createPosts = new SqlRun(this, 'Create Posts', {
vpc: vpc,
connection: SqlRunConnection.fromDatabaseInstance(db),
up: {
run: [{
sql: `CREATE TABLE posts(name varchar)`
}, {
sql: `INSERT INTO posts(name) VALUE (:secret)`,
parameters: {
secret: SqlSecret.fromSecretsManager(password)
}
}],
},
down: {
run: [{
sql: `DROP TABLE posts`
}]
}
});