Trying to find out how to create an Aurora Serverless V2 Cluster in CloudFormation? This is the article for you.
This is a great update for folks looking to integrate their Serverless V2 cluster in their Infrastructure as Code setup. So lets take a look at how to use CloudFormation to create our cluster and the options we have available to us.
Note that support for CDK does not seem to be available as of yet. I will update this post when more news arrives.
Step by Step Walkthrough
First, we need to give our cluster a name, and specify its type.
Note that V2 Clusters are the same Type setting as V1 clusters. The difference lies in the type of ScalingConfiguration we apply.
The DeletionPolicy is a setting that tells CloudFormation to delete our cluster’s resources upon deletion of the stack. Other options are Retain (prevents deletion), and Snapshot (snapshots the resource).
Now, we can define some Properties of the cluster.
The Engine specifies which type of DB engine we’d like to use. For Aurora v2, only three options are available:
aurora (for MySQL 5.6-compatible Aurora),
aurora-mysql (for MySQL 5.7-compatible Aurora), and
We also specify the MasterUsername and MasterUserPassword for our admin user. Note that its definitely a better idea to use IAM based authentication when access Aurora. You can check out my YouTube video here to learn how. For now, we’ll use plain text.
Next up, we need to define our scaling configuration. This is the setting that tells Aurora to create the V2 type.
Still under the Properties section, we specify a new property called ServerlessV2ScalingConfiguration. Within this property, you must specify two sub-properties: MinCapacity and MaxCapacity.
As a reminder, Min/Max Capacity refer to Aurora Scaling Units or ACUs. Each ACU corresponds to roughly 2GB of RAM and corresponding cpu / network capacity. The minimum value is .5 ACUs (1GB RAM) and maximum value is 128 ACUs (256GB RAM).
Note that Aurora Serverless V2 is “always on” and requires a minimum of .5 ACUs. This will cost you roughly $40 USD per month to run at a minimum. You can learn more on this in my recent article Amazon Aurora Serverless V2 – What is it and how does it work?
The entire code snippet looks like this:
After uploading the CloudFormation to AWS, you can see my stack was created and Aurora V2 database is now available!
Note that there are additional settings you can specify when creating your cluster. The settings specified above are the minimum required to get your cluster up and running. You can learn more from the AWS Serverless V2 Documentation.