Day 47: Test Knowledge on aws ๐Ÿ’ป ๐Ÿ“ˆ

Day 47: Test Knowledge on aws ๐Ÿ’ป ๐Ÿ“ˆ

ยท

6 min read

Today, we will be test the aws knowledge on services in AWS, as part of the 90 Days of DevOps Challenge.

Task-01

  • Launch an EC2 instance using the AWS Management Console and connect to it using SSH.

  • Install a web server on the EC2 instance and deploy a simple web application.

  • Monitor the EC2 instance using Amazon CloudWatch and troubleshoot any issues that arise

Launching an EC2 instance on AWS, installing a web server, deploying a simple web application, and monitoring with Amazon CloudWatch involves several steps. Here's a step-by-step guide:

Step 1: Launch EC2 Instance

Login to AWS Console:

  • Go to the AWS Management Console.

  • Sign in or create an AWS account.

  1. Navigate to EC2:

    • In the AWS Management Console, go to the EC2 Dashboard.
  2. Launch an Instance:

    • Click on "Instances" in the left navigation pane.

    • Click the "Launch Instance" button.

  3. Choose an Amazon Machine Image (AMI):

    • Select an AMI based on your requirements (e.g., Amazon Linux 2 AMI).
  4. Choose an Instance Type:

    • Select an instance type based on your needs.
  5. Configure Instance:

    • Configure the instance details, including the number of instances, network settings, etc.
  6. Add Storage:

    • Configure storage options based on your needs.
  7. Add Tags:

    • Add tags to your instance for better organization.
  8. Configure Security Group:

    • Configure security group rules to allow inbound traffic on port 22 (SSH) and any other ports your web application needs.
  9. Review and Launch:

    • Review your settings and click "Launch."

    • Select an existing key pair or create a new one to connect to your instance.

      Step 2: Connect to EC2 Instance

      1. Get Public IP:

        • Once the instance is running, note the public IP address.
      2. SSH into the Instance:

        • Open a terminal on your local machine.

        • Use the following command to connect to your EC2 instance:

            ssh -i "test_aws.pem" ubuntu@ec2-54-198-221-76.compute-1.amazonaws.com
          

          Replace /path/to/your/key.pem with the path to your private key and your-public-ip with your EC2 instance's public IP address.

Step 3: Install Web Server and Deploy Web Application

  1. Updating Package Manager: On the EC2 instance, update the package manager using the command

      sudo apt update -y
    

  2. Installing Apache Web Server: Install the Apache Web Server on the EC2 instance with the command

      sudo apt install apache2 -y
    

Step 3: Deploy a Simple Web Application

  1. Create a simple HTML file (e.g., index.html):

     echo "<html><body><h1>Hello from your EC2 instance!</h1></body></html>" | sudo tee /var/www/html/index.html
    

Open a web browser and navigate to your EC2 instance's public IP address. You should see the simple web application.

Monitoring EC2 Instance with Amazon CloudWatch

  1. Accessing AWS CloudWatch: Go to the AWS CloudWatch service in the AWS Management Console.

  2. Creating an Alarm: Click on "Create alarm" and select the EC2 metric you want to monitor, e.g. CPU utilization

  3. Configuring Conditions: Set up alarm conditions and notification settings as needed.

  4. Creating the Alarm: Give your alarm a name and create the alarm. This will trigger alerts based on the conditions you've set.

    Task-02

    • Create an Auto Scaling group using the AWS Management Console and configure it to launch EC2 instances in response to changes in demand.

    • Use Amazon CloudWatch to monitor the performance of the Auto Scaling group and the EC2 instances and troubleshoot any issues that arise.

    • Use the AWS CLI to view the state of the Auto Scaling group and the EC2 instances and verify that the correct number of instances are running.

Create a Launch Template: Begin by generating a 'Launch Template' from an EC2 instance.

  1. Launch Template Successfully Created: Confirm that the launch template has been successfully created.

  2. Commence Auto Scaling Group Creation: Initiate the process by clicking on the "Create Auto Scaling group" button.

  3. Select Launch Template: Choose the launch template to be applied to the instances within the group.

  4. Define Instance Type and Configuration: Specify the instance type and configure additional details, such as VPC, subnet, security groups, and storage.

  5. Establish Scaling Policies: Set up scaling policies to govern when new instances should be launched. Configure desired, minimum, and maximum capacity for instances.

  6. Choose Target Tracking Scaling Policy: Opt for the 'Target Tracking Scaling Policy' and select 'metric type' as CPU utilization, which will automatically create an alarm.

  7. Finalize Auto Scaling Group Creation: Click on "Create Auto Scaling group" to complete the creation of the auto-scaling group.

  8. Auto-Scaling Group Successfully Created: Confirm the successful creation of the auto-scaling group.

Use Amazon CloudWatch to monitor the performance of the Auto Scaling group and the EC2 instances and troubleshoot any issues that arise.

  1. Set Up Target Tracking Policy in Auto Scaling: Configure a target tracking policy in auto scaling that generates two distinct alarms with unique conditions.
  1. Monitoring Activation for Auto-Scaling Group: Once the alarms are in place, the monitoring of the specified metric for the Auto Scaling group begins. If the metric surpasses the set threshold, the alarm triggers and executes the predefined action.

  2. Enable Auto Scaling Group Metric Monitoring: Navigate to the auto-scaling group previously created, access the "Monitoring" tab, and activate "Auto Scaling Group Metric."

  3. Create Alarm via CloudWatch Dashboard: Alternatively, you can craft an alarm through the CloudWatch dashboard.

  4. Initiate Alarm Creation: Click on the "Create Alarm" button to initiate the alarm setup.

  5. Select EC2 as the Target: Navigate to the "EC2" section and choose 'By Auto Scaling Group.'

  6. Choose Metric for Monitoring: Pick the metric you wish to monitor, searching for it by name.

  7. Metric Selection and Alarm Setup: Select the desired metric and proceed to create an alarm.

  8. Monitoring and Triggering: Following alarm creation, continuous monitoring of the specified metric begins. If conditions are met, the configured action is triggered.

  9. Manage and Update Alarms: Monitor the alarm status in the CloudWatch console. Manage and update the alarm settings as required to ensure optimal functionality.

Use the AWS CLI to view the state of the Auto Scaling group and the EC2 instances and verify that the correct number of instances are running.

  1. AWS CLI Installation: Begin by installing the AWS CLI on your local machine using the following command:

      sudo apt-get install awscli
    
  2. AWS CLI Configuration: Configure the AWS CLI to establish the necessary connections and settings.

  3. Check Auto Scaling Group State: Utilize the command below to inspect the current state of the Auto Scaling group and the instances it manages:

      aws autoscaling describe-auto-scaling-groups
    
  4. Auto Scaling Group Instance Overview: Confirm that the Auto Scaling group has launched the specified number of instances (in this case, 2) by checking the desired capacity setting:

      aws ec2 describe-instances
    
  5. Instance Verification: Validate that the correct number of instances are not only running but also in a healthy and operational state.

You can also do stress test to check for auto-scaling and to check that our trigger is functioning.

For that use commands:

sudo apt-get install stress
stress --cpu $(nproc) --timeout 3600s

ย