Achieve Scalability and Agility: Refactoring My Web App on AWS (Part 2)

Can Yalcin
8 min readMar 31, 2024

--

B. Setting Up Your Database with RDS in AWS

Let’s dive into configuring the database for the project using Amazon Relational Database Service (RDS). Before creating the RDS instance itself, we need to set up a few things: subnets and parameter groups.

B.1. Creating a Database Subnet Group

  1. Navigate to RDS Service: Head over to the RDS service on the AWS Management Console.
  2. Access Subnet Groups: On the left-hand menu, click on the option labeled “Subnet groups.”
  3. Create a New Group: Click the button that says “Create DB subnet group.”
  4. Provide Group Details: Enter a descriptive name for your group (e.g., “MyProjectDatabaseSubnets”). Optionally, you can add a brief description to further clarify its purpose.
  5. Select VPC: From the dropdown menu, choose the default VPC (Virtual Private Cloud) in your account.
  6. Add Subnets: Scroll down to the “Add subnets” section. Here, you’ll see a list of availability zones within your region. By default, all the available zones and their corresponding subnets will be selected. This ensures high availability for your database instance.
  7. Create the Group: Once everything looks good, click the “Create” button to bring your database subnet group to life!

B.2. Fine-tuning your RDS with Parameter Groups

While Amazon RDS offers a managed service, there might be times you want to customize how your database operates. That’s where parameter groups come in. Think of them as dials and switches for your RDS instance. They let you fine-tune settings without needing to directly access the database itself (since SSH login is not possible into RDS!).

Here’s how to create a parameter group:

  1. Navigate to Parameter Groups: Find the RDS section of your AWS Management Console and look for “Parameter Groups”.
  2. Create a New Group: Click on “Create parameter group” to get started.
  3. Select your Database Flavor: A dropdown menu will appear. Choose “MySQL 8.0” (or the specific version you’re using).
  4. Give it a Name and Description: Pick a clear and descriptive name for your parameter group (e.g., “High Performance Settings”). Optionally, add a brief description of what this group does.
  5. Let’s get tweaking! Once you click “Create”, your parameter group is ready. Click on it to see a detailed list of configurations you can adjust.

A friendly word of caution: Unless you’re comfortable with database parameters, it’s best to leave the advanced options alone. However, this gives you a glimpse into the level of control parameter groups offer for optimizing your RDS instance.

B.3. Creating a MySQL Database on Amazon RDS

Here’s a breakdown of the steps:

1. Choosing the Creation Method and Engine

  • Log in to the AWS Management Console and navigate to the RDS service.
  • Click on “Create database” to begin the setup process.
  • Select “Standard create” as the database creation method.
  • Choose “MySQL” as the engine type and select the specific version you want (e.g., 8.0 for this project).

2. Specifying Database Details

  • Under “Templates,” you can choose “Dev/Test” for a development environment or “Free tier” for a limited free option (check AWS documentation for eligibility).
  • Under “Availability & durability,” select “Single AZ database instance” for a basic setup.

3. Configuration Settings

  • Provide a name for your RDS instance.
  • Keep the username as “admin” and enable the option to auto-generate a secure password.
  • Scroll down to “Instance Class” and choose “Burstable classes” followed by a specific class like “db.t3.micro” for a cost-effective option.

4. Storage and Security

  • Under “Storage,” select “General Purpose (SSD) (gp2)” as the storage type.
  • Decrease the allocated storage to 20 GB to accommodate your project needs.
  • In the “VPC security group” section, remove the default selection and choose the “backend security group” you created earlier (refer to Part 1 for creating a security group).

5. Additional Configuration

  • In the “Initial database name” field, enter “accounts” (ensure correct spelling for this project).
  • Just below, select the parameter group you created beforehand.

6. Enabling Logs

  • Scroll down to “Log exports” and enable checkboxes for all log types: Audit log, Error log, General log, and Slow query log. This provides valuable data for monitoring and troubleshooting.

7. Review and Create

  • At the bottom of the page, you’ll see an estimated monthly cost. Remember, this is for demonstration purposes only. You can delete the database later to avoid incurring charges.
  • Once you’ve reviewed all the settings, click on “Create database” to provision your RDS instance.

Once the database creation window appears, look for the “View Credential Details” option in the top right corner.

Click on “View Credential Details”. This will reveal the username and password you generated during database creation.

Important: The password is auto-generated and won’t be displayed again after you close this window. So, be sure to copy and save both the username and password somewhere secure. You’ll need them later to update your application’s properties file.

Once you’ve copied the credentials, feel free to close the window.

C. ElastiCache instance:

Before diving into creating your ElastiCache instance, you’ll need to set up a subnet group. This group defines a collection of subnets within your Virtual Private Cloud (VPC) where your ElastiCache cluster can reside. Here’s how to create one:

C.1. Creating a subnet group

  1. Navigate to Subnet Groups: Locate the “Subnet Groups” section within the ElastiCache console.
  2. Click “Create subnet group”: This will launch the subnet group creation wizard.
  3. Provide a name and description: Choose a clear and descriptive name for your subnet group that reflects its purpose. Optionally, add a brief description to further explain its function.
  4. Select your VPC: From the dropdown menu, choose the VPC where you want to deploy your ElastiCache cluster.
  5. Include all Availability Zones: Ensure all Availability Zones within your chosen VPC are selected. This provides redundancy and fault tolerance for your ElastiCache cluster.
  6. Click “Create”: Once you’ve reviewed and confirmed your selections, click the “Create” button to finalize the subnet group creation.

C.2. Creating an ElastiCache Cluster with a Custom Parameter Group

We’ll create a custom parameter group to configure the cluster and then launch the cluster itself.

1. Define the Parameter Group

  • Navigate to ElastiCache Parameter Groups. You can usually find this section within the ElastiCache console.
  • Click “Create Parameter Group.”
  • Name your Parameter Group and provide a Description. Choose a clear name that reflects its purpose. The description can be used to document any specific configurations within the group.
  • Select Memcached 1.6 from the Engine Version dropdown. This should match the version you plan to use for your cluster.
  • Click “Create” to finalize the Parameter Group.

2. Launch the Memcached Cluster

  • Go to the ElastiCache Clusters section and select “Create Memcached Cluster.”
  • Choose “Standard Create” and ensure “AWS Cloud” is selected.
  • Give your Cluster a Name and Description. Similar to the Parameter Group, use descriptive names for clarity.
  • Scroll down to Cluster Settings.
  • Under Engine Version, select Memcached 1.6 to match your Parameter Group.
  • Leave the Port as the default 11211.
  • In the Parameter Group dropdown, select the one you just created.
  • Choose the smallest Node Type (e.g., t2.micro with 0.5 GiB RAM). This is a cost-effective option for basic workloads.
  • Set the Number of Nodes to 1. You can scale this up later if needed.
  • Ensure your Memcached Subnet Group is selected.
  • For Availability Zone, you can choose “No Preference” unless you have specific requirements.
  • Click “Next” to proceed.

3. Configure Security and Launch

  • On the Advanced Settings page, under Selected Security Group, click “Manage.”
  • Choose your Backend Security Group from the list. This group controls access to your cluster.
  • Review all the details on the next page, paying close attention to the Node Type (t2.micro) and Security Group selection.
  • Once everything is confirmed, click “Create” to launch your Memcached Cluster.

D. Setting Up Amazon MQ for RabbitMQ in Just a Few Steps

Amazon MQ makes it easy to deploy a RabbitMQ message broker service in AWS. Here’s a step-by-step guide to get you started:

  1. Navigate to Amazon MQ and Create a Broker: Log in to your AWS Management Console and search for Amazon MQ. Click on “Create brokers” to begin the setup process.
  2. Select Engine and Broker Type: Choose “RabbitMQ” as the engine for your message broker. In the next step, select “Single instance broker” for a basic deployment.
  3. Configure Broker Details:
  • Name: Give your broker a descriptive name that reflects its purpose.
  • Instance Type: Select the “t3.micro” instance type. This is the most lightweight option available.
  • Credentials:
  • Enable “Show password” to view the username and password generated for your broker.
  • Important: Make sure to securely store these credentials as you’ll need them later to connect your applications to the broker.
  • Configure Network and Security:
  • Access Type: Choose “Private access” to restrict broker access from within your VPC (Virtual Private Cloud).
  • Security Group: Under “Security group,” select the existing security group associated with your backend application. This ensures proper communication between your application and the broker.
  • Review and Create:
  • Carefully review the configuration details on the summary page, especially the username and password.
  • Once everything looks correct, click on “Create broker” to provision your RabbitMQ service on AWS.

Remember: The credentials you noted down earlier will be crucial for connecting your applications to the newly created Amazon MQ broker.

While we wait for the creation process to finish, let’s grab the endpoint address for your RDS database.

1. Head back to your AWS Management Console and navigate to the RDS service. Make sure you’ve selected the same region where your database resides.

2. Find your database instance in the list and click on its name. This will open a detailed view of your RDS instance.

3. Look for the “Connectivity & Security” section. This section displays important information about how to connect to your database.

4. Within “Connectivity & Security,” you’ll find the endpoint address of your RDS instance. This address typically follows a format like your-database-id.account-id.region.rds.amazonaws.com.

5. Copy the endpoint address and save it in a secure location. You’ll need this address later to update your application’s properties file.

Next Steps (Part 3): Initializing the RDS Database

Now that we’ve created our RDS database instance, it’s time to initialize it. This involves deploying our SQL file to set up the database structure.

Since we can’t access the RDS instance directly from the public internet for security reasons, we’ll need to launch an instance within the same Virtual Private Cloud (VPC) as the database. This temporary instance will be used to execute the SQL file and initialize the database.

There’s no need to wait for everything to be fully set up before starting the initialization. As soon as your RDS instance is available, you can launch the temporary instance within the VPC and begin the process.

If you need to go back to Part 1:

--

--

Can Yalcin
0 Followers

This blog is my space to share my projects and keep my DevOps and FinOps notes organized and accessible for future reference.