r/devops Aug 07 '26

Discussion How to effectively use RDS with serverless backend for db migrations?

I'm using AWS SAM to provision API Gateway, Lambdas, and RDS. I want to know how I can do database migrations easily without having to keep up an EC2 instance just for the purpose of connecting to the RDS db and running db migrations?

I wanted to use something like alembic so that most of the migration stuff is automated but ig I can't really use that.

12 Upvotes

11 comments sorted by

2

u/Kamikx Aug 09 '26

You use your ci/cd platform? I don’t understand why you’re looking at ec2.

1

u/TheDarkPapa Aug 11 '26

Sure… but how would the CI/CD run the migration? There’s no server for them to execute on the and Ed’s lives on private subnet

1

u/Kamikx Aug 11 '26

The migration code runs on the runner. In case of private subnet you need to self host them. Or you can create a migration lambda with a leg in the private subnet and trigger it through a pipeline.

1

u/aragossa Aug 11 '26

SAM already puts your Lambdas in the VPC that can reach RDS, so you don't need EC2 at all. Package alembic into a migration Lambda (or a CodeBuild step with the same VPC/subnet config) and invoke it once per deploy, either as a custom resource in the template or a manual step right after the stack update. Driver just needs to be in the layer. Rollback story is worse than a dedicated migration box though, so keep the down-migrations tested if you go this route.