Serverless Aurora Schema


I’ve recently started using Aurora Serverless and I have everything up and running in terms of infrastructure, but I’m having some issues when it comes to actually setting up the database itself.

So, when my stack finishes deploying I have a lambda function that runs immediately the sole responsibility of which is to set up the database tables.

I have a sql file that defines the table creation queries which as it stands, I am bundling with my lambda reading it from disk, splitting the file at ; to separate each query then using the Data API to run them in sequence.

This works and I suppose does the job, but it feels wrong. MySQL has import / export functionality, is there anyway you can define the schema of the database at creation, or run a sql file without having to manually separate the queries and manage their execution?

Thanks for any help!

What I usually do is creating a bastion host (ec2) with SSH connection only, and then stablish a connection through this ec2. In my opinion this is way more flexible and easier than managing it through lambda functions - and also can be done automatically using serverless. The only thing you’ll have to do is connecting to the bastion host and running your script - or even create a script that does it all after the serverless deploy is successful, thus making your aurora db setup happen soon after it’s deployed.

I’m really curious if there’s a better way than automating this process, because I am using serverless less than a year, so this possibility is totally plausible.