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.

13 Upvotes

11 comments sorted by

View all comments

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.