Aurora Serverless v2 creation using CloudFormation

Aurora Serverless v2 creation using CloudFormation. AWS_EN

Aurora Serverless v2 creation using CloudFormation

In the following pages, we have shown you how to create Aurora Serverless v1 using CloudFormation.

It was announced that Aurora Serverless v2 will also support CloudFormation on 2022/10/05.

Amazon Aurora Serverless v2 now supports AWS CloudFormation

This page uses CloudFormation to create Aurora Serverless v2.


Diagram of Aurora Serverless v2 creation using CloudFormation.

The basic structure is the same as the page introduced at the beginning of this document.

Create Aurora Serverless v2 and associate it with two subnets with different AZs.
For DB engine, specify the latest version of MySQL type.

Create an EC2 instance.
Use it as a client to connect to Aurora Serverless.
The OS will be the latest version of Amazon Linux 2023.

CloudFormation template files

The above configuration is built with CloudFormation.
The CloudFormation templates are placed at the following URL

Explanation of key points of template files

Aurora Serverless v2

When creating Aurora Serverless v2 using CloudFormation, three resources are created.
Many parameters for each resource are the same as when creating a regular Aurora.
In this case, we will focus on parameters specific to Aurora Serverless v2.

DB Subnet Group

    Type: AWS::RDS::DBSubnetGroup
      DBSubnetGroupName: dbsubnetgroup
      DBSubnetGroupDescription: test subnet group
        - !Ref DBSubnet1
        - !Ref DBSubnet2
Code language: YAML (yaml)

No special configuration is required here.
Specify two or more subnets on which to place the DB clusters described below.

The point is the AZ where each subnet is created.
Note that each must be created in a different AZ.

Aurora Cluster

    Type: AWS::RDS::DBCluster
      DatabaseName: !Ref DBName
      DBClusterIdentifier: !Sub "${Prefix}-dbcluster"
      DBSubnetGroupName: !Ref DBSubnetGroup
      Engine: !Ref DBEngine
      EngineVersion: !Ref DBEngineVersion
      MasterUsername: !Ref DBMasterUsername
      MasterUserPassword: !Ref DBMasterUserPassword
        MaxCapacity: 1.0
        MinCapacity: 0.5
      StorageEncrypted: true
        - !Ref DBSecurityGroup
Code language: YAML (yaml)

There are three points.

The first point is the Engine property.
In Aurora Serverless v2, you can choose MySQL or PostgreSQL as the DB engine.
Since we will create a MySQL type Aurora Serverless v2, we will specify “aurora-mysql” for this property.

The second point is the EngineVersion property.
This property allows you to specify the DB engine version.

Refer to the following page to check the versions that can be specified using the AWS CLI.

Requirements for Aurora Serverless v2 - Amazon Aurora
Learn about the requirements for Aurora Serverless v2.

The version of the MySQL type that can be selected in the ap-northeast-1 region can be checked with the following command.

$ aws rds describe-orderable-db-instance-options \
--engine aurora-mysql \
--db-instance-class db.serverless \
--region ap-northeast-1 \
--query 'OrderableDBInstanceOptions[].[EngineVersion]' \
--output text
Code language: Bash (bash)

In this case, specify “8.0.mysql_aurora.3.03.1” which is the latest version as of July 2023.

The third is the ServerlessV2ScalingConfiguration property.
This property defines the range of performance (ACU) that can be taken by the DB instances created in the cluster.

The unit of measure for Aurora Serverless v2 is the Aurora capacity unit (ACU).

Each ACU is a combination of approximately 2 gibibytes (GiB) of memory, corresponding CPU, and networking. You specify the database capacity range using this unit of measure.

Aurora Serverless v2 capacity

ACU values can be specified from 0.5 to 128 in increments of 0.5.
For this verification, we specify 0.5 as the minimum possible ACU value and 1.0 as the maximum (MinCapacity and MaxCapacity properties).

DB Instance

    Type: AWS::RDS::DBInstance
      DBClusterIdentifier: !Ref DBCluster
      DBSubnetGroupName: !Ref DBSubnetGroup
      DBInstanceIdentifier: !Sub "${Prefix}-dbinstance"
      DBInstanceClass: !Ref DBInstanceClass
      Engine: !Ref DBEngine
      AvailabilityZone: !Sub "${AWS::Region}${AvailabilityZone}"
      PubliclyAccessible: false
Code language: YAML (yaml)

The DBInstanceClass property is the key.

db.serverless – A special DB instance class type used by Aurora Serverless v2.

Aurora Serverless v2 instance class type

According to the above, “db.serverless” is specified for this property.

Security Group

    Type: AWS::EC2::SecurityGroup
      GroupName: !Sub "${Prefix}-DBSecurityGroup"
      GroupDescription: DBSecurityGroup.
      VpcId: !Ref VPC
        - IpProtocol: tcp
          FromPort: !Ref MySQLPort
          ToPort: !Ref MySQLPort
          SourceSecurityGroupId: !Ref InstanceSecurityGroup
Code language: YAML (yaml)

Security group to be applied to the Aurora cluster.
The settings are the same as for a normal MySQL type RDS instance.
Allow inbound communication to the port for MySQL communication (tcp/3306).
For the Source, specify the security group to be applied to the EC2 instance described below.

(Reference) EC2 instance

    Type: AWS::EC2::Instance
      IamInstanceProfile: !Ref InstanceProfile
      ImageId: !Ref ImageId
      InstanceType: !Ref InstanceType
        - DeviceIndex: 0
          SubnetId: !Ref InstanceSubnet
            - !Ref InstanceSecurityGroup
      UserData: !Base64 |
        #!/bin/bash -xe
        dnf update -y
        dnf install -y mariadb105
Code language: YAML (yaml)

This instance is used to access Aurora Serverless v2.

So we install mariadb using the user data function.
Now prepare the client for MySQL.

For more information on the EC2 instance initialization process, please also see the following page.


Use CloudFormation to build this environment and check its actual behavior.

Create CloudFormation stacks and check the resources in the stacks

Create CloudFormation stacks.
For information on how to create stacks and check each stack, please see the following page.

After reviewing the resources in each stack, information on the main resources created in this case is as follows

  • EC2 instance: i-0ea84706be1475b7f
  • Aurora cluster: fa-138-dbcluster
  • Aurora cluster endpoint:

Check the Aurora cluster from the AWS Management Console.

Detail of Aurora 1.

The Aurora cluster has been successfully created.
And one DB instance is created in the cluster.

Detail of Aurora 2.

Looking at the DB instance type, we see that it was indeed created as Aurora Serverless v2.
The capacity information shows that the ACU is set between 0.5 and 1.0.

Operation Check

Now that you are ready, access the EC2 instance.
The SSM Session Manager is used to access the instance.

% aws ssm start-session --target i-0ea84706be1475b7f
Code language: Bash (bash)

For more information on SSM Session Manager, please refer to the following page.

Next, check the installation status of the MySQL client.

sh-5.2$ dnf list installed | grep mariadb
mariadb-connector-c.aarch64            3.1.13-1.amzn2023.0.3              @amazonlinux
mariadb-connector-c-config.noarch      3.1.13-1.amzn2023.0.3              @amazonlinux
mariadb105.aarch64                     3:10.5.18-1.amzn2023.0.1           @amazonlinux
mariadb105-common.aarch64              3:10.5.18-1.amzn2023.0.1           @amazonlinux
Code language: Bash (bash)

You can see that MariaDB is indeed installed.

Check the version.

sh-5.2$ mariadb -V
mariadb  Ver 15.1 Distrib 10.5.18-MariaDB, for Linux (aarch64) using  EditLine wrapper
Code language: Bash (bash)

You will see that the latest version of the client is installed.

Now that the client installation has been verified, connect to Aurora Serverless v2.
Specify the Aurora cluster endpoint and pass the port number, username and password as arguments.

sh-5.2$ mariadb -h -P 3306 -u testuser -p testdb
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 97
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [testdb]>
Code language: Bash (bash)

We were able to connect successfully.
Aurora Serverless v2 was successfully created.


Aurora Serverless v2 was created with CloudFormation.