Highly Available Web Server with CloudWatch Alarms
One day you may be responsible for an Application or Server Infrastructure that will require the highest availability for those requiring the services. AWS Services such as EC2, CloudWatch and Auto Scaling Policies assist with providing such availabilities. The following documented project helped me understand how these cloud services work together to provide crucial availability to some of the most critical infrastructures the world over. In addition, I hope my project helps someone learn additional skills or assist with a better understanding of the technology as it has for me.
I have annotated as best as I could to demonstrate my steps and should be an easy understanding to follow along, Enjoy!
Let’s Begin:
A.) Open your Browser and go to the AWS Login page to access your account.
Once logged in, the AWS Management console will open.
In the AWS Management Console, Search for services or select VPC under the Networking and Content Delivery section. In the VPC Dashboard, move down to select Your VPCs or click VPCs on the right menu.
B.) Click Create VPC, under VTC Settings; fill in the following:
a. Name Tag
b. IPv4 CIDR block
c. Click Create VPC
When the Create subnet screen appears, lets configure the Subnet.
C.) In the VPC ID drop-down list, select the VPC you just created
a. Add a Subnet name
b. Select your Availability Zone drop the drop-down list
c. Enter your IPv4 CIDR
d. Click Create subnet
Let’s navigate to the All services menus; On the top left of your AWS console, click the Services down arrow to display the menu option of Services.
A.) Under the Compute section, click and select EC2
B.) After the EC2 Dashboard opens, in the left menu, scroll down to the Auto Scaling section and click Launch Configurations
Click Create launch configuration
C.) At the Create launch configuration page, let’s fill in some information:
a. Launch configuration name — Add a Name
b. Amazon machine image (AMI) — Select from the drop-down list
c. Instance type — Click the Choose instance type box to select
The Additional configuration — optional section is under the Instance type box.
D.) Click Advanced details
Scroll down to the User data section to copy & paste your script;
Skip down to the Security groups section.
E.) In Security groups;
a. Add a Security group name
b. In Rules, be sure the an SSH rule is established as shown with your source subnet
c. Select Create key pair under Key pair options, click Download key pair, then click Create launch configuration
While still in the EC2 Dashboard, we’ll create an Auto Scaling group to help you manage your CPU requests as demand grows or decreases when your Web Server is being accessed.
A.) On the left menu, scroll down to the Auto Scaling section, click Auto Scaling Groups
Click Create an Auto Scaling group
There are six steps of configurations to an Auto Scaling group, I’ll configure the first four, the remaining three are optional and for this project I will not use them.
Let’s get started:
1. Choose launch template or configurations:
a. Add a Name for the Auto Scaling group, click Switch to launch configuration, select your launch configuration from the drop-down list
Click Next
2. Configure Settings:
a. For the Network section, you’ll select your VPC and Subnets from their respective lists
Click Next
3. Configure advance options:
a. Leave default selections in place
Click Next
4. Configure group size and scaling policies:
a. Change Minimum capacity to 2
b. Change Maximum capacity to 5
Click Next
5. Click Next two times, then click Create Auto Scaling group
Note: For this project I bypassed Steps 5 and 6 however in a production environment I’d recommend the configurations for these steps.
Adding a CPU Utilization Policy for Scaling-In and Scaling-Out through CloudWatch:
- Select the Auto Scaling group you created
- Click the Automatic scaling tab then, Add policy
3. Change Policy Type to Simple scaling
4. Add a Scaling policy name to the policy
5. Click Create a CloudWatch alarm under the CloudWatch alarm drop-down
6. Click Select metric
7. Click EC2
8. Click By Auto Scaling Group
9. Find and select the Metric for CPUUtilization, click Select metric
10. Leave all defaults in place except the Define the threshold value. Click Next
11. On the Configure actions page, select a notification SNS topic from the Send a notification to… drop down list, click Next
12. Add an Alarm name for CloudWatch, adding an Alarm description is optional, click Next
13. Review your configuration when it’s displayed to you, if you like everything you entered, click Create alarm
Summary: Steps 1 through 13 above walked you through creating a Scale-Out Policy through the EC2 service and alarms through the CloudWatch service, you can repeat the same steps to create your Scale-In policy and alarm to complete the Auto Scaling configuration for your Web Servers High Availability.
Testing Failover:
This screenshots shows three instances; the first two was running until I terminated the second. During the process of it terminating, the third instance came online and began initializing to complement the first instance and ensuring the Web Server experiences Zero downtime making it Highly Available.
Project by: Eric Ingram
April 21, 2021