Multi-tier Architecture on AWS

About

Build a multi-tier architecture project with various AWS services for real time environments.
Alt Text

  • R53 - To create record sets within hosted zones.
  • VPC - To create subnets, internet gateway, route tables, security groups.
  • SNS - For notification services.
  • ELB - For load balancing.
  • ACM - For SSL certificates.
  • EC2 - Instances with elastic IP and Auto Scaling group attached.
  • RDS - Master database with multi - AZ configuration.

Steps :

1. Public and private subnets, IGW, NAT Gateway,etc.

VPC
Alt Text
Public Subnet - 1
Alt Text
Public Subnet - 2
Alt Text
Private Subnet - 1
Alt Text
Private Subnet - 2
Alt Text
Created
Alt Text
IGW
Alt Text
Attached to VPC
Alt Text
Private Route table for VPC
Alt Text
Alt Text
NAT Gateway with attached Elastic IP
Alt Text
Associate private subnets with NAT Gateway
Associate NAT gateway to Private RT
Alt Text
Attach private subnets to Private RT
Alt Text
Attach IGW to Public RT
Alt Text

VPC setup completed!

2. Create EC2 instance with Userdata (Bootstrapping) script.

EC2 setup complete!

3. Create RDS Security Group and RDS subnet group with Private Subnets.

Create security group
Alt Text
Provided access to only webserver SG
Alt Text
Create Database
Type - MySQL
VPC - Komla-VPC
SG - Security group for incoming traffic from EC2 on port 3306.
Instance - db.t2.micro
Alt Text
Alt Text
Alt Text
Alt Text

Database created!
Create ELB
Alt Text
VPC - Komla-VPC
Alt Text
Spread across Public subnets
Alt Text
Create SG for load balancer
Alt Text
Health check parameters
Alt Text
Add EC2 instance
Alt Text
Alt Text
ELB created!
Alt Text
Apache server operating. EC2 instance healthy!

4. Launch RDS instance with Multi-AZ.

5. Install WordPress.

Latest version of WordPress requires atleast php 5.6. Amazon t2 micro comes with php 5.4 standard. To bypass this issue I installed php 7. Refer.

sudo amazon-linux-extras install -y php7.2
           sudo service httpd restart

Installing Wordpress: Official tutorial
wget https://wordpress.org/latest.tar.gz
Alt Text
Extracted the downloaded package from wordpress with
tar -xzf latest.tar.gz
Alt Text
Moved the contents of wordpress directory to /var/www/html
Alt Text
cd /etc/httpd/conf
edit httpd.conf
Alt Text
Search for "AllowOverride None" change None to All.
It is in /var/www/html directory.
Change permissions on html directory.
chown -R apache:apache /var/www/html.
Alt Text
Wordpress opens on the Public IP of EC2 instance!
http://18.***.161.241/wp-admin/setup-config.php
Alt Text
Check whether RDS is accessible via EC2 instance.
Alt Text
After configuring the dbname,username, password, hostname the wordpress application is up and running on Public IP of EC2 instance on the browser!
Alt Text

6. Create Route53 hosted zone to map with domain.

The ELB DNS is configured as an A record for the domain name wordpress.komlalebu.com.
Alt Text

7. Create AMI for EC2.

Alt Text

8. Create ELB.

The EC2 instances are now accessed with the ELB DNS.
Alt Text

9. Create launch configuration from AMI.

Alt Text
Running two desired instances
Alt Text

10. Create ASG for launch configuration.

VPC - Komla-VPC
Subnets - Public subnets
ELB - Komla-ELB
Desired - 2 instances
Minimum - 1 instances
Maximun - 2 instances
Alt Text
Alt Text
Alt Text
Alt Text

Scaling policy
Alt Text

11. Health Check and fault tolerance.

Terminated all instances created by Auto Scaling for testing.
Alt Text
Health check failed and a new instance was created from AMI with ASG.
Alt Text
Notification received in mail whenever instances are terminated or launched.
Alt Text
Alt Text
Website up and running within minutes of server failure!

20