Trying to find out how to create an Aurora Serverless V2 Cluster in CloudFormation? This is the article for you.
AWS recently announced CloudFormation support for Amazon Aurora Serverless v2. If you missed it, you can check out my article for a summary of the new features available.
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.
ServerlessV2Cluster: Type: 'AWS::RDS::DBCluster' DeletionPolicy: Delete
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.
Properties: Engine: aurora-mysql MasterUsername: daniel_admin MasterUserPassword: my_super_secure_password
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.
ServerlessV2ScalingConfiguration: MinCapacity: 0.5 MaxCapacity: 2
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:
ServerlessV2Cluster: Type: 'AWS::RDS::DBCluster' DeletionPolicy: Delete Properties: Engine: aurora-mysql MasterUsername: daniel_admin MasterUserPassword: my_super_secure_password ServerlessV2ScalingConfiguration: MinCapacity: 0.5 MaxCapacity: 2
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.
Thanks Daniel.. I started down the terraform route and I’m just puzzled so heading back to Cloudformation. Can’t figure out why I’d want to do this with terraform anyway.
Is there a particular reason aws doesn’t just write up a JSON/YAML full template and we are left to rummage for the bits?
Thanks for the instructions. But does this also create serverless v2 instances like when I do it in console?
Hey Daniel. Thank you for the instruction, seems only one so far for ServerlessV2Cluster.
We need to create SubnetGroup and ParameterGroup for the Cluster. How to refer them within Serverless Cluster.
Moreover, other configurations as Encryption,VPC etc. where can be applied ?
Woudl be really helpful if you can share a template with all options.