Test Knowledge on AWS
PermalinkTask-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.
Initiate the instance creation process by clicking the "Launch Instance" button.
Opt for an Amazon Machine Image (AMI) to assign to the instance.
Tailor the instance type according to your specific needs and preferences.
Customize instance details like VPC, subnet, security groups, and storage. Click on 'Launch instance' to proceed.
Once the instance is successfully created, access it by clicking on the "Connect" button and view the connection details.
Establish a connection to the instance using the SSH client.
Install a web server on the EC2 instance and deploy a simple web application.
After establishing a connection to the instance, proceed by upgrading the package manager and installing a web server such as Apache or Nginx. In this example, we've installed the nginx server using the following command:
sudo apt-get install nginx
Initiate the nginx service and verify its status.
Navigate to the directory /var/www/html.
Generate a new index.html file containing a straightforward HTML form.
Access the web application by browsing the public IP, showcasing the newly created simple web page.
Monitor the EC2 instance using Amazon CloudWatch and troubleshoot any issues that arise.
Establishing CloudWatch Alarms: Utilize CloudWatch Alarms to configure alerts based on specific conditions or thresholds. Design alarms for diverse metrics, including CPU utilization, memory usage, disk space, and more. To illustrate, to establish a CPU utilization alert, proceed as follows:
Navigate to the CloudWatch Management Console.
In the left menu, select "Alarms" and then click on "Create Alarm."
Choose the metric you wish to monitor (e.g., “Per-Instance Metrics” > “EC2” > “Per-Instance Metrics” > “CPUUtilization”).
Customize the alarm conditions (e.g., select “Threshold type” as static, define the threshold, and specify the evaluation period).
Configure actions to execute when the alarm state is triggered, such as initiating an SNS notification.
PermalinkTask-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.
Launch Template Successfully Created: Confirm that the launch template has been successfully created.
Commence Auto Scaling Group Creation: Initiate the process by clicking on the "Create Auto Scaling group" button.
Select Launch Template: Choose the launch template to be applied to the instances within the group.
Define Instance Type and Configuration: Specify the instance type and configure additional details, such as VPC, subnet, security groups, and storage.
Establish Scaling Policies: Set up scaling policies to govern when new instances should be launched. Configure desired, minimum, and maximum capacity for instances.
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.
Finalize Auto Scaling Group Creation: Click on "Create Auto Scaling group" to complete the creation of the auto-scaling group.
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.
- Set Up Target Tracking Policy in Auto Scaling: Configure a target tracking policy in auto scaling that generates two distinct alarms with unique conditions.
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.
Enable Auto Scaling Group Metric Monitoring: Navigate to the auto-scaling group previously created, access the "Monitoring" tab, and activate "Auto Scaling Group Metric."
Create Alarm via CloudWatch Dashboard: Alternatively, you can craft an alarm through the CloudWatch dashboard.
Initiate Alarm Creation: Click on the "Create Alarm" button to initiate the alarm setup.
Select EC2 as the Target: Navigate to the "EC2" section and choose 'By Auto Scaling Group.'
Choose Metric for Monitoring: Pick the metric you wish to monitor, searching for it by name.
Metric Selection and Alarm Setup: Select the desired metric and proceed to create an alarm.
Monitoring and Triggering: Following alarm creation, continuous monitoring of the specified metric begins. If conditions are met, the configured action is triggered.
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.
AWS CLI Installation: Begin by installing the AWS CLI on your local machine using the following command:
sudo apt-get install awscli
AWS CLI Configuration: Configure the AWS CLI to establish the necessary connections and settings.
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
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
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
See the instances going upto 4 and the CPU utilization increasing.
Thankyou for reading until here. See you in the next one. Happy Learning!