Test Knowledge on aws ๐Ÿ’ป ๐Ÿ“ˆ

Test Knowledge on aws ๐Ÿ’ป ๐Ÿ“ˆ

Day 47

ยท

10 min read

Task-01

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

  • Here's a step-by-step guide to launching an EC2 instance using the AWS Management Console and connecting to it using SSH:

    1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

    2. Open the EC2 Dashboard by searching for "EC2" in the AWS Management Console search bar and selecting "EC2" under the "Compute" section.

    3. Click on the "Launch Instance" button to start the instance creation wizard.

    4. Choose an Amazon Machine Image (AMI)

      • Select an AMI based on your requirements. For example, you can choose an Amazon Linux 2 AMI or an Ubuntu Server AMI.

    5. Choose an Instance Type

      • Select the desired instance type based on your workload requirements. For example, you can choose t2.micro for a primary, low-cost instance.

      • Select an existing key pair or create a new one.

        • If you already have an existing key pair, select it from the drop-down menu. Otherwise, create a new key pair and download the .pem private key file. This key pair is necessary to connect to the instance using SSH.

  1. Configure Instance Details

    • Set the necessary configurations, such as the number of instances, network settings, security groups, etc. You can also add user data or customize advanced options if needed.

    • Create a new security group or select an existing one. Make sure to allow inbound SSH traffic (port 22) to connect via SSH. You can also configure additional rules based on your requirements.

  2. Add Storage (optional)

    • Configure the storage requirements for your instance. By default, an EBS volume will be attached to the instance for the root device. You can modify the size, type, and additional volumes as needed.

  3. Review Instance Launch

    • Review your configuration settings. If everything looks good, click on "Launch" to proceed.

    • Click on "Launch Instances."

  4. Once the instance is launched, you can connect to it using SSH.

    Here's how:

    In the EC2 Dashboard, select your instance from the list.

    Click on the "Connect" button at the top of the page.

    In the "Connect to your instance" section, you will see the SSH command to connect to your instance. It will look something like this:

     ssh -i /path/to/keypair.pem ec2-user@<Public-IP-or-DNS>
    

  5. Open your preferred terminal or SSH client and run the SSH command. Make sure to replace /path/to/keypair.pem it with the actual path to your private key file and <Public-IP-or-DNS> with your instance's public IP address or public DNS name.

    If prompted, confirm connecting by typing "yes."

    You should now be connected to your EC2 instance via SSH.

That's it! You have successfully launched an EC2 instance using the AWS Management Console and connected to it using SSH.

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

To install a web server on your EC2 instance and deploy a simple web application, you can follow these general steps:

  1. Connect to your EC2 instance using SSH, as mentioned in the previous response.

  2. Update the package repository and install the web server software. The commands may vary based on the operating system you are using on your EC2 instance. Here are some examples:

     sudo apt update
     sudo apt install -y apache2
    
  3. Start the web server:

      sudo systemctl start apache2
    
  4. Verify that the web server is running by accessing your instance's public IP address or public DNS name in a web browser. You should see the default page of the web server.

  5. Next, deploy your simple web application. You can create an HTML file or copy your existing web application files to the appropriate location.

    the default document root is /var/www/html/.

    Navigate to the document root directory:

     cd /var/www/html/
    

    Create or upload your HTML or web application files to this directory.

  6. Once your files are in place, you can access your web application by entering your instance's public IP address or public DNS name in a web browser. You should see your deployed web application.

That's it! You have now installed a web server on your EC2 instance and deployed a simple web application. Keep in mind that these steps provide a general overview, and depending on your specific application requirements, you may need to perform additional configuration or setup tasks.

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

To monitor your EC2 instance using Amazon CloudWatch and troubleshoot any issues, you can follow these steps:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the CloudWatch service by searching for "CloudWatch" in the AWS Management Console search bar and selecting "CloudWatch" under the "Management & Governance" section.

  3. In the CloudWatch console, navigate to the "Metrics" section in the left-hand navigation pane.

  4. Under the "EC2" category, select the metrics you want to monitor for your EC2 instance. Some commonly monitored metrics include CPU utilization, network traffic, disk usage, and memory usage. Choose the appropriate metric(s) based on your monitoring needs.

  5. Click on the checkbox next to the desired metric(s) and then click on the "Create Alarm" button.

  6. In the "Create Alarm" wizard, configure the alarm settings based on your requirements. This includes setting thresholds, specifying the period, and defining actions to be taken when the alarm state is triggered. For example, you can set a CPU utilization threshold of 80% and configure CloudWatch to send a notification or trigger an auto-scaling action if the threshold is breached.

  7. Once you have configured the alarm settings, click on the "Create Alarm" button to create the alarm.

  8. CloudWatch will now start monitoring the selected metric(s) for your EC2 instance based on the configured alarm. If any issues arise, such as high CPU utilization or low disk space, CloudWatch will trigger the alarm and perform the defined actions.

To troubleshoot any issues identified by CloudWatch, you can take the following steps:

  1. When an alarm is triggered, you can navigate to the "Alarms" section in the CloudWatch console to view the status of the alarms. Look for the alarm associated with your EC2 instance.

  2. Click on the alarm name to view detailed information about the triggered alarm, including the metric values and the alarm history.

  3. Analyze the metric data to identify the root cause of the issue. For example, if the CPU utilization is high, it could indicate that the instance is under heavy load or that a particular process is consuming excessive resources.

  4. Use CloudWatch logs and CloudWatch Insights to gain further insights into your EC2 instance's logs and perform advanced log analysis. You can enable CloudWatch logs for your EC2 instance and configure log groups and log streams.

  5. If necessary, take appropriate actions to resolve the issue based on the troubleshooting findings. This could involve optimizing your application, adding more resources to the instance, or investigating specific processes causing the problem.

By monitoring your EC2 instance with CloudWatch and troubleshooting any issues that arise, you can ensure the smooth operation of your application and promptly address any performance or resource utilization problems.

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.

A step-by-step guide to creating an Auto Scaling group using the AWS Management Console and configuring it to launch EC2 instances in response to changes in demand:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the EC2 Dashboard by searching for "EC2" in the AWS Management Console search bar and selecting "EC2" under the "Compute" section.

  3. In the EC2 Dashboard, click on "Auto Scaling Groups" in the left-hand navigation pane.

  4. Click on the "Create Auto Scaling group" button to start the Auto Scaling group creation wizard.

  5. Choose the launch template or configuration

    • Select the method for creating instances. You can choose either a launch template or a launch configuration. A launch template provides more flexibility, so it is recommended to use that option.

    • Click on "Create a new launch template" or "Create a new launch configuration" to proceed with creating the template or configuration.

  6. Configure details

    • Provide a name for your Auto Scaling group.

    • Set the instance size, network, and subnet settings.

    • Select the appropriate VPC and subnets for your instances.

    • Specify the desired capacity and minimum/maximum number of instances to scale.

  7. Review

    • Review your configuration settings. If everything looks good, click "Create Auto Scaling group" to create the group.

  8. Once the Auto Scaling group is created, it will start launching EC2 instances based on the specified configurations and scaling policies.

That's it! You have successfully created an Auto Scaling group using the AWS Management Console and configured it to launch EC2 instances in response to changes in demand. The Auto Scaling group will automatically adjust the number of instances based on the defined scaling policies and the demand of your application.

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

To monitor the performance of your Auto Scaling group and EC2 instances using Amazon CloudWatch and troubleshoot any issues, you can follow these steps:

  1. Sign in to the AWS Management Console at https://console.aws.amazon.com.

  2. Open the CloudWatch service by searching for "CloudWatch" in the AWS Management Console search bar and selecting "CloudWatch" under the "Management & Governance" section.

  3. Target tracking policy in autoscaling creates 2 alarms with 2 different conditions.

    Once the alarm is set up, it will start monitoring the specified metric for the Auto Scaling group. If the metric exceeds the threshold that you have set, the alarm will be triggered and take the action that you have specified.

  4. Go to the auto-scaling group that we created, Click on the "Monitoring" tab and enable "Auto scaling group metric"

  5. You can also create an alarm by going to the CloudWatch dashboard.

    Click on the "Create Alarm" button to set up an alarm.

    Click on "EC2".

    Click on 'By Auto Scaling Group'.

    Choose the metric you want to monitor. You can search for the metric by name.

    Select any metric which you want to monitor and create an alarm.

    Once the alarm is created, it will start monitoring the specified metric and trigger the configured action if the conditions are met. You can view the status of the alarm in the CloudWatch console, and manage and update the alarm settings as needed.

By monitoring your Auto Scaling group and EC2 instances using CloudWatch and troubleshooting any issues that arise, you can ensure the optimal performance, availability, and scalability of your applications running in the AWS environment.

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.

To view the state of the Auto Scaling group and the EC2 instances using the AWS Command Line Interface (CLI) and verify the number of instances running, you can use the following AWS CLI commands:

  1. Install and configure the AWS CLI on your local machine.

    Install aws cli using the command

     sudo apt-get install awscli
    
  2. Configure AWS CLI

     aws configure
    
  3. To check the state of the Auto Scaling group, use the describe-auto-scaling-groups command:

aws autoscaling describe-auto-scaling-groups

  1. To view the running EC2 instances associated with your Auto Scaling group, you can use the describe-auto-scaling-instances command:
aws ec2 describe-instances

Replace <Auto-Scaling-Group-Name> with the name of your Auto Scaling group. This command will display information about the instances currently associated with your Auto Scaling group.

By executing these AWS CLI commands, you can view the state of your Auto Scaling group, check the associated EC2 instances, and verify the number of instances currently running. This allows you to ensure that the desired number of instances are operational and properly managed by the Auto Scaling group.

Thankyou....

ย