Configure and Connect to Serverless MySQL Database

with Amazon Aurora Serverless

In this tutorial, you will learn how to configure and connect to Amazon Aurora Serverless.

Amazon Aurora is a relational database service with MySQL and PostgreSQL-compatible editions, which offers the performance and availability of enterprise databases at a fraction of the cost. Aurora Serverless is a new on-demand auto-scaling configuration for Aurora which is now generally available for the Aurora MySQL-compatible edition. With Aurora Serverless, your database will automatically start up, shut down , and scale up or down capacity based on your application’s needs – so you’re never paying for what you don’t use, while still benefiting from Aurora’s high availability, scale, and speed.

Traditionally, database administration requires a fair amount of guesswork: keeping ahead of unknowable and sometimes volatile compute and storage growth for new applications, managing variable workloads like development and test databases, and keeping lots of database capacity online - only for it to be used infrequently. With Aurora Serverless, you can eliminate the guesswork. Aurora Serverless grows your database storage and compute capacity when your application needs it, and shrinks capacity when your app needs less. You pay on a per-second basis for the database capacity you use when the database is active, and migrate between standard and serverless configurations with a few clicks in the Amazon Web Services Management Console.

In the next few minutes, you will create and configure a new Aurora Serverless DB cluster. To access your new Aurora Serverless cluster, you will create a Cloud9 environment and then enable network traffic to the cluster from your Cloud9 environment. Using the MySQL command line tool installed on your Cloud9 environment, you will login to your cluster. Finally, you will clean up and terminate your Cloud9 environment and Aurora Serverless DB cluster.

This tutorial is not within the free tier and will cost you less than $1 provided you follow the steps in the tutorial and terminate your resources at the close of the tutorial.

Manage Your Amazon Web Services Resources

Step 1. Navigate to the Amazon RDS console

In this step, you will navigate to the Amazon Relational Database Service (Amazon RDS) console so you can create an Aurora Serverless DB cluster.

a.  Open the Amazon Web Services Management Console, so you can keep this step-by-step guide open. When the screen loads, enter your user name and password to get started. Then begin typing Amazon RDS in the search bar and select Amazon RDS to open the service console.

( click to enlarge )

Step 2. Create an Aurora Serverless DB cluster

In this step, you will use Amazon RDS to create an Aurora Serverless DB cluster.

a. On the Amazon RDS screen, from the navigation bar on the left, select Clusters.

( click to enlarge )

b. From the Amazon RDS > Clusters screen, select Create database.

( click to enlarge )

c.  On the Select engine screen, select Amazon Aurora. In the Edition radiobuttons, select MySQL 5.6-compatible. Currently, only the MySQL 5.6 version is available with Aurora Serverless.

Select Next.

( click to enlarge )

d.  On the Specify DB details screen, under Capacity type select the Serverless radio button.

In the Setting pane, in the DB cluster identifier field enter MyClusterName.

Set the Master username and Master password fields with values of your choice and store the username and password for further use later.

( click to enlarge )

e.  On the Configure advanced settings page, in the Capacity setting pane, you can change the Minimum Aurora capacity unit and the Maximum Aurora capacity unit settings.

Each Aurora capacity unit is equivalent to a specific compute and memory configuration. Aurora Serverless will automatically scale between the minimum and maximium capacity settings based on your cluster's CPU utilitization, connections, and available memory.

Expand the Additional scaling configuration section. You can disable cluster pausing by unchecking the Pause compute capacity after consecutive minutes of inactivity checkbox. Using the hours, minutes, and seconds drop down list boxes, you can change the length of inactivity time until the cluster pauses. By default your cluster will pause after 5 consecutive minutes of inactivity.

For this tutorial, you should leave these default values.

( click to enlarge )

f. On the Network & Security pane, in the Virtual Private Cloud (VPC) list, select Create new VPC.

In the Subnet group list, select Create new DB Subnet Group.

In VPC security groups list, select Create new VPC security group. You will modify this new security group to allow network traffic from your database client to access your new Aurora Serverless cluster in a later step.

Select Create database.

( click to enlarge )

g.  The Amazon RDS > Clusters screen will load and your MyClusterName cluster will appear as in the creating status. Click on MyClusterName in the cluster list to access detailed information about your cluster.

( click to enlarge )

h.  The MyClusterName detail screen will load. This screen contains monitoring information including the Serverless Database Capacity graph that shows the number of Aurora Capacity Units in use over time and Recent Events pane which details scaling and pausing/resume events.

Scroll to the to the Details pane. Record the VPC value and Database endpoint values for use later in the tutorial.

( click to enlarge )

Step 3. Create a Client Environment with Cloud9

After creating the MyClusterName cluster, your next task is to create a database client inside the same VPC. To complete this task you will create a Cloud9 environment to use as your database client.

a.  From the top Amazon Web Services Web Console menu, select Services. In the search bar, begin typing Cloud9 and select Cloud9 to open the service console.

( click to enlarge )

b. On the Amazon Cloud9 screen, select Create environment.

( click to enlarge )

c.  On the Name environment screen, in the Name field type MyCloud9Env and select Next step.

( click to enlarge )

d.  On the Configure setting screen, leave the environment type as Create a new instance for environment (EC2) and the Instance type as t2.micro.

( click to enlarge )

e.  Because Aurora Serverless DB clusters do not have publically accessible endpoints, your MyClusterName can only be accessed from within the same VPC.

To place MyCloud9Env in the same VPC as MyClusterName, scroll down the Configure setting screen and expand the Network settings (advanced) section. From the Network (VPC) drop down, select MyClusterName's VPC which you recorded step 2h.

Select Next step.

On the Review page, select Create environment.

After your new Cloud9 environment has been created, proceed to the next step.

( click to enlarge )

Step 4. Enable client network access to your Serverless Cluster

In this step, you will enable network access from your Cloud9 environment to your Serverless DB Cluster. To accomplish this task, you will add the security group assigned to MyCloud9Env as a traffic source for the security group assigned to MyClusterName. A security group is a virtual firewall that controls network traffic in your network.

a.  To make navigation easier, load the Amazon Web Services Web Console in another browser tab by clicking here. In the new browser window, on the top menu bar, select Services then type VPC in the search bar and select VPC from the list.

( click to enlarge )

b.  On the VPC Dashboard page, in the left navigation select Security groups.

In the Group Name column, find the security group that begins with aws-cloud9-MyCloud9Env. Note the Group ID of this security group.

As an example, in the screen shot to the right, you would note the security group that ends with 7431. Your Group ID will be different than is pictured in this screen shot.

( click to enlarge )

c.  In the list of security groups, select the security group that begins with RDS-Launch-Wizard.

Then select the Inbound Rules tab.

Then select Edit.

( click to enlarge )

d.  In the Inbound Rules tab, select Add another rule.

In the Type column, select MySQL/Aurora (3306) from the drop down list.

Then click into the Source column field and a drop down list will appear. Select the security Group ID that you noted in step 4b. Then select Save.

As an example, in the screen shot to the right, from the list you would select the security group that ends 7431. Your specific Group ID will be different than is pictured in this screen shot.  

( click to enlarge )

Step 5. Connect to your Aurora Serverless DB Cluster

In this step, from your Cloud9 environment you will access your Aurora Serverless DB cluster.

a.   Switch back to your MyCloud9Env browser window.

In the bash terminal tab in MyCloud9Env, type in the following command. Substitute your Master username and database endpoint for the values in the command and press Enter.

mysql --user=[your Master username] --password -h [your database endpoint]

When prompted, enter your Master password and press Enter.

You should now be connected to the MyClusterName Aurora Serverless DB cluster! 

( click to enlarge )

b. You can issues commands to the Aurora Serverless DB cluster using the connection you have established. For example, you can show the databases on the server by pasting the following command into the MyCloud9Env bash tab:

show databases;

( click to enlarge )

Step 6. Terminate resources

In this step you will terminate your Aurora DB cluster and Cloud9 environment.

Important: Terminating resources that are not actively being used reduces costs and is a best practice. Not terminating your resources will result in a charge.

a.  From the top menu, select Services, then begin typing RDS in the search bar. Select RDS to go back to the Amazon RDS Console.

( click to enlarge )

b.  From the Amazon RDS console page, select Clusters from the left navigation list. From the Clusters list, select myclustername. From the Actions menu select Delete Cluster.

When prompted to delete myclustername, select Delete DB Cluster.

( click to enlarge )

c.  From the top Amazon Web Services web console menu, select Services. In the search bar, begin typing Cloud9 and select Cloud9 to open the service console.

( click to enlarge )

d. From the Your environments screen, select MyCloud9Env and select Delete. Confirm the MyCloud9Env deletion.

( click to enlarge )


Now that you have learned to create and connect to an Aurora Serverless database cluster, you can progress to the Aurora Serverless user guide, where you can learn to restore, modify, view, and set capacity for your Aurora Serverless databases.

Using Amazon Aurora Serverless »