Showing posts with label AWS. Show all posts
Showing posts with label AWS. Show all posts

Amazon RDS

 

How to configure an Amazon RDS environment for MySQL

In this article, I am going to explain how to configure the RDS MySQL Environment in AWS. RDS is the Relational Database Service Available from the Amazon which enables us to spin up any relational database instance without having to worry about the infrastructure behind it. Users can connect to this instance very easily and start building database applications with ease. This article will focus more on how to configure the RDS MySQL Environment and not much on the MySQL details.

Although there are different tiers available to install the RDS MySQL Environment, we will just explore the free tier of the RDS service. You can spin up an instance as required if you need to. Depending upon the processors and time, the service charge for the databases may vary. Using the free-tier, users are eligible to use the RDS service for free up to 750 hours a month and I think that is enough for the service to run without incurring any additional charges.

1. Setting up the RDS environment

Configuring the RDS MySQL Environment by first signing up for an AWS Account. Once you have successfully created the AWS account, search for RDS in the Find Services bar and hit enter.

RDS MySQL Environment

Figure 1 – Searching for AWS RDS

Open the RDS from the drop-down menu and proceed to create the RDS MySQL Environment. On the next page that appears, click on Create Database. This will open another page where you can define the necessary details required to set up the MySQL Database.

Create Database Button in AWS RDS

Figure 2 – Create Database Button in AWS RDS

2. Creating the MySQL database

Once you click on the Create Database, a new page opens as follows, where you can define the database creation method and other options. We are going to select Standard Create as the database creation method. This will allow us to configure all the necessary settings on our own. Next, select the Engine Type as MySQL and the latest version. At the time of writing this article, the latest MySQL version in 8.0.16.

Selecting the Database Engine

Figure 3 – Selecting the Database Engine

In the next step, we are going to provide the name and connection details for the MySQL Database that we are going to create. Since we are going to create the database in the free tier, select the Free Tier from the template and proceed. for example, I’m going to use the database instance as “mysql-db-test01”. Similarly, provide a suitable master username and password for the same. This is the username and the password, that you will be using later to connect to this MySQL instance later. Also, you must keep these credentials safe so that it can be used later again.

Setting up the Instance Credentials

Figure 4 – Setting up the Instance Credentials

Now, that the instance credentials have been set up, let’s go ahead and set some other properties which are essential to set up the RDS MySQL Environment. Select the Database Instance Size as “db.t2.micro” and Storage Type as General Purpose SSD. By default, the memory size is allocated to 20GB which is fine for the moment.

Specifiying the DB Instance Size

Figure 5 – Specifying the DB Instance Size

In the next step define the Connectivity settings for the RDS Database instance. Select the default VPC connection that is already available within your login. For my use case, I have already created some RDS instances previously, so I’ll be using the same VPC for this instance as well. Additionally, we should also add a Subnet Group within the VPC connection. Since we will be accessing the database instance from outside the AWS Environment, we should enable the Publicly Accessible to Yes. Finally, for VPC Security Group, select “Choose Existing” and proceed forward.

Configuring Connectivity Settings for RDS MySQL Environment

Figure 6 – Configuring Connectivity Settings for AWS RDS

Now that most of the configuration is done, in the final step we are creating the database  Database Authentication Mode as Password Authentication. Once completed, click on Create Database.

Create Database in AWS RDS

Figure 7 – Create Database in AWS RDS

3. Configuring the RDS MySQL Environment

Once you click on Create Database in the previous step, it might take a while for AWS to create the RDS instance and make it available for use. After a few moments, you will receive a notification that says the database has been created successfully.

RDS MySQL Environment Created Successfully

Figure 8 – RDS Instance for MySQL Created Successfully

As you can see in the figure above, I have already created an RDS instance for SQL Server previously, the newly added MySQL Community instance is also added to the Databases list. Go ahead and click on the DB Identifier for the MySQL Database. A new page will open containing more information about the MySQL database instance. The important thing in here is the Endpoint which is available. This endpoint information will be used later to connect to the instance using the MySQL Workbench tool.

MySQL Database Instance

Figure 9 – MySQL Database Instance

The next step here is to allow connections from the public network to allow and connect to the instance. In order to enable this, click on the VPC Security Groups and then open the new page.

VPC Security Groups

Figure 10 – VPC Security Groups

In the following page that appears, select the Security Group ID and open it.

Security Group ID

Figure 11 – Security Group ID

In the Security Group page, select the Edit Inbound Rules button. This will allow us to edit the IP addresses that will have access to the MySQL Database instance.

Select Edit Inbound Rules

Figure 12 – Select Edit Inbound Rules

The Edit Inbound Rule page appears. On this page, we will add a custom rule which allows any IP address to connect to the RDS Instance on the port 3306. The port 3306 is the default port of MySQL is usually configured. If you are using any other port, you should allow traffic to that particular port instead.

Click on the Add Rule button and select the Source as Anywhere. This will allow all traffic from outside the AWS environment to connect to the MySQL instance on the RDS. Click on Save Rules once done.

Allow Inbound Connections

Figure 13 – Allow Inbound Connections

You can see that the new rules have been added to the list and are now effective.

Added Inbound Rules for MySQL

Figure 14 – Added Inbound Rules for MySQL

4. Connecting to the RDS environment using MySQL Workbench

We will be using MySQL Workbench to connect to the RDS instance. You can also choose any other tool to connect to the instance and it will work the same.

Enter the endpoint that we copied in the previous steps as the hostname and the master username as the username here and click on Test Connection.

Connecting to the RDS Instance

Figure 15 – Connecting to the RDS Instance

You might be prompted to provide the password in the next step.

Password to connect to RDS

Figure 16 – Password to connect to RDS

If the connection is successful, you will receive a notification saying the connection has been successful.

MySQL Connection Successful

Figure 17 – MySQL Connection Successful

You can now go ahead and create your own schemas and tables in the RDS Instance.

Connected to RDS Instance

Figure 18 – Connected to RDS Instance

Conclusion

Amazon RDS is the relational database service offered by AWS using which it is very easy to start any RDBMS without worrying much about the infrastructure. In this article, we have seen how to configure the RDS MySQL Environment in AWS. We have also seen how to create the MySQL instance and how to allow remote connections to it from an external server. Finally, we have connected to the RDS MySQL Environment using the MySQL Workbench in local and executed simple queries.

Launch a static website using AWS S3 buckets

Launch a static website using AWS S3 buckets

This article explores the 

AWS S3 bucket to configure a static website.


Introduction

Amazon Web Services (AWS) has an object-level storage solution known as Simple Storage Service. We can store any kind of file in this cloud service. It gives you unlimited storage and a maximum of 5TB single file upload.

In the articles listed below, we explored S3 bucket integration with AWS RDS SQL Server using the web console, and AWS CLI commands.

We can use s3 buckets for hosting a static website. In many cases, we do not require a dynamic website where data changes very frequently. For example, suppose you publish technical articles on SQL Server. It is a static website as users open the website and read the content. We can leverage the s3 bucket for hosting a static website using AWS serverless architecture.

Let’s start configuring the static website using the AWS S3 bucket.

AWS S3 bucket configuration

Logon to AWS web console and search for S3 service. It lists the existing buckets in your AWS account if any.

AWS S3 bucket configuration

Click on Create Bucket to configure a new s3 bucket that holds contents for our static website. Give a unique bucket name and choose the appropriate region to deploy your AWS resources.

Create Bucket

AWS does not allow public access for s3 bucket, by default. We need to edit this behavior for a static website. Click Next, and you see default behavior – Block all public access.

Block all public access

Remove the tick from the block all public access. It also gives you a warning message, and you need to acknowledge that you operated intentionally.

Accept warning

Review the bucket configuration and click on Create bucket.

Create bucket

You can see the newly configured S3 bucket in the below screenshot.

Configured S3 bucket

Now, open the bucket and go to Permissions -> Bucket Policy.

bucket policy

It opens the bucket policy editor. We can specify the policy in the JSON format. Paste the following JSON code with your bucket name.

bucket policy editor.

Create a static website using HTML

You should create a static website in your local system and test if it is working correctly or not. For this article’s demo purpose, I create a basic HTML website.

It uses the following HTML files.

  • Index.html: This file contains the content of the static website

  • Error.html: It is a custom error HTML page. In case of any error, by default, you receive an error such as HTTP 404 Not Found. You can configure an error web page instead of this default page. I use the following HTML code for error documents

Upload static website files to an AWS S3 bucket

I have the following files for my static website:

static website files

Browse to the S3 bucket and upload all files in the bucket we created earlier.

Upload static website files to S3 bucket

After uploading these files, select all files and go to actions-> Make public.

Make public

It highlights the public access to this bucket resources explicitly, as shown below.

Public access

Configure static website hosting in the AWS S3 bucket

We need to configure the S3 bucket for hosting a static website. Open the bucket and navigate to properties. Here, you get bucket configurations such as versioning, server access logging and static website hosting.

Configure static website

By default, static website hosting is disabled. Click on the box and do the following configurations.

  • Select option – Use this bucket to host a website
  • Specify the index document name. In my case, it is index.html
  • Specify the error document name. In my case, it is error.html

These index.html and error.html should be available in the s3 bucket with public access.

Use this bucket to host a website

You should note-down the Amazon S3 website endpoint specified in the static website hosting page. Click on Save, and you see a tick mark in the bucket hosting property in static website hosting.

Bucket hosting

Now, open the endpoint URL in a web browser, and you should be able to launch your serverless static website using an S3 bucket.

Endpoint URL

Similarly, you can view the error HTML page in the web browser.

Error page

Accessing AWS Static Website with your domain Name

In the above steps, we accessed a static website using the endpoint. Usually, for a website, you require a user-friendly name like www.example.com

It is not convenient for users to remember the endpoint name. You might not get a good response for your website even it has relevant content. For this purpose, we can use the existing domain name or purchase a custom domain name. I do not have any domain names so let’s buy it from Amazon.

In the services, launch Amazon Route 53. It gives you the following options.

Accessing AWS Static Website with your domain Name

Click on the domain registration. Search for the domain name, and it shows you the price for different domains. Its price may vary in different domains. You can select the lowest price domain and click Next.

Register a domain

Enter your contact details such as first name, last name, address, contact number.

Enter contact details

Click Continue. Verify details entered, accept terms & conditions and verify the email address of the registered contact.

Accept terms & conditions

Check your registered email and click on the link received from Amazon Registrar. Once verification has competed, it shows verified status.

Amazon Registrar

Click on complete order. It processes the order and debits the payment from your registered payment method in the AWS account.

Order for a domain

It takes some time to register your customized domain. You can view your domains in the registered domain section of Route53.

Registered domain

Create DNS ‘A’ record for custom domain

DNS ‘A’ record refers to an IP address of the specified domain. It holds an IPv4 address. Click on the hosted zones, and it shows your registered domain.

Create DNS ‘A’ record for custom domain

Click on the domain name, and it shows you pre-configured hosted zones. A hosted zone is like a container that has routing information for a domain. You can refer to Working with hosted zones for more details.

Hosted zones

To create domain ‘A’ name, click on the Create record set. It opens a create recordset window.

Specify the following values:

  • Name: It shows the name of the domain in the recordset name. We can go with the default value
  • Type: Choose value A – IPv4 address from the drop-down list
  • Alias: Choose Yes to create an alias

Alias Target: In the alias target, select the s3 bucket name. This bucket name should match with the custom domain. It lists the s3 bucket in the drop if it fulfills following conditions

  • AWS S3 bucket should be configured as a static website
  • The bucket name and the A record name should be the same
  • Both the S3 bucket and A record should be in the same AWS account

Create record set

If you do not get the AWS S3 bucket name in the alias target, we can specify the Amazon S3 website endpoint for the region that consists of our S3 bucket for static website.

For my S3 bucket in the Asia Pacific (Mumbai) region, it has endpoint s3-website.ap-south-1.amazonaws.com. Once you specify the endpoint, it shows alias hosted zone ID. You can get the region-specific Amazon S3 website endpoint and hosed zone id from the AWS docs.

Endpoint for different regions

Specify the website endpoint, verify the hosted zone id and create the DNS ‘A’ record set.

Alias target

It quickly creates the ‘A’ record, as shown below.

A record

We can test the newly created record set as well. Click on the Test record set.

Test record set.

Specify your system IP and click on Get response. It checks the response from Route 53, and you get the following output. In case of any error, it shows you an error message.

Get response

Now, you can test your Amazon S3 static website using the custom domain. Open a web browser, specify the domain, and it launches the website as shown below.

Access static website using custom domain

In case you specify a wrong URL, it navigates to the error page that we configured during static website configuration.

Wrong URL redirects to error page

Conclusion

In this article, we traversed the configuration of a static website using the AWS S3 bucket. We also used a custom domain to launch the static website. You can create the website pages, upload them into an S3 bucket, and users can access the website. You do not require to maintain any backend servers. It is a serverless architecture, and AWS manages them for you automatically.