Welcome back to the final installment of this series!
Today we will be launching our servers, configuring CloudWatch & adding resilience to our instances.
- Part 1: Manually Configure a VPC
Part 2: Secure the Network Environment
Part 3: Launching Servers, CloudWatch/Resilience
Create IAM Role for CloudWatch Agent
IAM roles allow you to delegate access to users or services that normally don't have access to your organization's AWS resources. IAM users or AWS services can assume a role to obtain temporary security credentials that can be used to make AWS API calls.
Before we launch our App server in the private subnet, let's create an IAM role that our Web Server instance will utilize for CloudWatch.


Under Add Permissions
Type "cloudwatchagent" and press enter
Under Name, Review, and Create:



Launch App Server Instance in the Private Subnet of the SmallProjectA VPC
Amazon Elastic Compute Cloud (Amazon EC2) provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates your need to invest in hardware upfront, so you can develop and deploy applications faster








- After launching, Click the instance ID in the banner


Launch Web Server Instance in the Public Subnet of the SmallProjectA VPC
In this next task, you will create an ec2 instance for the web server that will run on the public subnet.
- The web server will communicate with the application server through the PrivateSubnetACL network ACL and the APPSG security group.
Launch Ec2 Instance in Public Subnet 1 and enter the following:
Launch Instance - Obtain Instance Public IP via Instance Dashboard > Details
yum update -y
amazon-linux-extras install epel -y
yum install stress -y
yum install -y httpd php
systemctl start httpd
systemctl enable httpd
echo '<center><h1><?php echo $_SERVER["SERVER_ADDR"]; ?></h1></center><br><br><?php phpinfo(); ?>' > /var/www/html/index.php
echo '<?php error_reporting(E_ERROR); $fp = fsockopen("APPSERVERIP", 80, $errno, $errstr, 1); if (!$fp) {echo "<h1>Success</h1>";} else {echo "<h1>Fail</h1>"; fclose($fp);}Test Web Server
Test Web Server
Success! We can successfully connect to our instance which indicates we have a connection to the App server.

SSH Into Web Server via Ec2 Instance Connect
Amazon EC2 Instance Connect is a simple and secure way to connect to your instances using Secure Shell (SSH).




!!! We are unable to connect to our instance... lets find out why.

When using EC2 Instance Connect, an HTTPS connection is established between your computer and the EC2 Instance Connect Service inside AWS. The Ec2 Connect Service then establishes an SSH connection to the EC2 instance. We will need our security group to allow SSH traffic for IP range 18.206.107.24/29 for the EC2 Connect Service in us-east-1.
The IP ranges for the EC2 Instance Connect service can be found here: https://ip-ranges.amazonaws.com/ip-ranges.json
Add SSH Traffic to WebServerSPASG Security Group


Installing & Starting CloudWatch Agent
CloudWatch Agent is a software package that autonomously and continuously runs on your servers. Using CloudWatch Agent, we can collect metrics and logs from Amazon Elastic Compute Cloud (Amazon EC2), hybrid, and on-premises servers running both Linux and Windows
- Install and Configure CloudWatch Agent via CLI
sudo yum install amazon-cloudwatch-agent -y
- Initialize CloudWatch Config Wizard
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
The Wizard will go through a variety of options, ensure the following config is set: For any other parameter not specified, use default value
CollectD Monitoring
Do you want to monitor any host metrics? e.g CPU,memor, etc.
Would you like to collect metrics at High Resolution?
Which Default Metrics do you want?
Do you want to Monitor Log Files?
Log File Path?
- /var/log/httpd/access_log
Monitor Additional Log Files
Store config in SSM Parameter Store?
Accept above content of config
Start the CloudWatch Agent via snippet below
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
Create CloudWatch Alarm for Memory Usage
Amazon CloudWatch is a monitoring and management service that provides data and actionable insights for AWS, hybrid, and on-premises applications and infrastructure resources.












Testing CloudWatch MemoryAlert alarm
stress -m 1 --vm-bytes 700M


After some time, the alarm should revert back to an OK state. Click on the Memory Alert alarm to review the alarm history.
We can see that our stress test spiked the utilization of memory in our instance and action was taken by our CloudWatch alarm to remedy over utilization.



Great Job! Kudos to you if you've stuck through and completed this mini series. Although we ran into an issue with connecting to our instance, overall we were successful in implementing our tasks without issue.
Thank you for joining me on this three-part series...be sure to clean up any infrastructure that may have been provisioned so that you do not incur any charges.
Remove Infrastructure:
VPC Dashboard
Ec2 Dashboard
- Terminate Web Server / App Server
CloudWatch Dashboard
Finally - Delete SmallProjectAVPC
* This will delete all resources associated with VPC
Till next time!