Sma Ma
Sma Ma

Reputation: 3685

how to setup tables of aws aurora mysql using aws cloudformation or aws cdk?

how to setup tables of aws aurora mysql using aws cloudformation or aws cdk?

in my setup i have a serverless app using lambda for various microservices. the datebase is a serverless aurora mysql database. to provision the aws infrastructure i will use aws CDK. i like to setup the database using some migration tools like liquibase or sequelize.

for the moment i am using a separat lambda function. the lambda function executes liquibase to setup db changes. but i have to execute the function separately after deployment with CDK is succeded.

an execution triggered after the execution of the cloudformation stack (cdk stack) would be optimal?! I would like to avoid a CI / CD stack via code pipeline.

does anyone has best practice to setup database at provision time?

Upvotes: 2

Views: 2209

Answers (2)

Murali Allada
Murali Allada

Reputation: 22918

I use Cloudformation custom resources for running database migrations and initial database setup scripts at deployment time.

This is the recommended way for running DB migrations for serverless applications if you don't want to rely on a CI/CD pipeline to do it for you.

Here's a well written blog post by Alex DeBrie about CF custom resources: https://www.alexdebrie.com/posts/cloudformation-custom-resources/

Upvotes: 1

Sma Ma
Sma Ma

Reputation: 3685

Cloud watch rules

Cloud watch rules based on cloudformation events can be used to route events for processing lambda. Cloud watch rules can be a part of the CDK deployment description.

The triggered function can then execute liquibase, flyway, sequelize or something else to spinup or change db.

---- or ----

Cloudformation custom resource

AWS cloudformation custom ressource can execute a lambda function during cloudformation lifecycle.

The triggered function can then execute liquibase, flyway, sequelize or something else to spinup or change db.

Upvotes: 3

Related Questions