Friday, 13 October 2017

Wordpress AWS Part 2 - RDS

Before we start anything, we need to understand 2 things in Amazon.

1. Region


We select the "region" first, then the resources (RDS, EFS, EC2, etc) are set up in the selected "region". Elastic File System is not available in the "Asia Pacific (Singapore)" region.

EFS is not supported in Singapore.
We need to to make sure we are... elsewhere, Sydney in this case...

We are in Sydney.
... then we start setting up our RDS, EFS, etc.

2. Security Groups and Inbound Rules


Amazon's resources are placed into one or more "security groups". Take for example, this load balancer is in secuity group "sg-99e25dff".

This load balancer is in security group "sg-99e25dff".
Security groups have "inbound rules". Inbound rules have to be created if we want something to be able to reach a resource. In this example, we want the world to be able to reach the load balancer which is in security group "sg-99e25dff". Thus, there should be an inbound rule that looks like...

Allowing the world to reach the load balancer.
Similarly, if all our EC2 instances are in security group "sg-a3e15ec5", and we want our load balancer (in security group "sg-99e25dff") to be able to reach our EC2 instances, there should be an inbound rule that looks like...

Allowing the load balancer to reach the EC2 instances.

In the above example, the security groups and inbound rules were automatically created by Beanstalk when we create an application environment. If we manually create anything else, such as an RDS for example, we need to make sure the security groups and inbound rules are done up properly as well.

With these 2 things out of the way, let's start creating.

RDS


We are now creating an RDS database. Easiest to get there, use the search box.

Using the search box...
Click "Get Started Now".
Choose "MySQL".
DB engine version: MySQL 5.7.17 (the version that works with Wordpress)
DB instance class: db.t2.micro
Storage type: General Purpose (SSD)
Allocated storage: 5GB (The more storage you get, the more IOPS Amazon will allocate to you. For us, 5GB should be enough.)
DB instance identifier: quekdbinstance (or anything you choose)
Master username: quekDBmasteru (or anything you choose, this is the MySQL root)
Password: (your desired password for the master username)
Public accessibility: Yes (we need this if we want to transfer data from existing database outside Amazon, like when we need to migrate client's database into Amazon.)
Availability zone: No preference
VPC security groups: (We are leaving it as the "default" security group.)
Database name: quekwordpressDB (or anything you choose)
Database port: 3306
Everything else leave as default and click "Launch DB instance".

When it is all done, it should look something like this...

DB launched.
How can we connect to this database? Click on the database instance, scroll down a bit, and look out for "Endpoint"...

The "Endpoint" of the database.

... which is actually the hostname of the database server. With any mysql client, using this "Endpoint" and the "Master username" and password that we specified earlier, we can connect to it from anywhere (because we configured "Public accessibility: Yes" and if we also configured the appropriate inbound rules for the appropriate security group). Here's an example...

Connecting to our RDS...
We can now use this database for our new Wordpress, or for migrating client's data into it using the usual "mysqldump ... > dumpfile.sql" and "mysql ... < dumpfile.sql" should work.

Part 1 - Overview
Part 2 - RDS
Part 3 - EFS
Part 4 - Key Pairs
Part 5 - Beanstalk
Part 6 - ebextensions Folder
Part 7 - Deploy Wordpress
Part 8 - 4000 Concurrent Connections