Skip to main content

Creating and Working with an EC2 Instance

Hands-On Lab

 

Photo of

Training Architect

Length

00:45:00

Difficulty

Beginner

Elastic Compute Cloud (EC2) is AWS's Infrastructure as a Service product. It provides a huge range of virtual machines suitable for general purpose and specialized on-demand compute tasks. In this hands-on lab, you will gain experience creating and interacting with an EC2 instance. The lab covers EC2 requirements, the choices available with creating EC2 instances, and the provisioning process itself. By the end of the lab, you will have gained the experience needed to be confident using EC2 in smaller deployments, such as blogs or lower-volume websites.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating and Working with an EC2 Instance

Introduction

In this hands-on lab, we will create and interact with an EC2 instance. The lab covers EC2 requirements, the choices available with creating EC2 instances, and the provisioning process itself.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Here are the instructions on how to connect to EC2 using PuTTY on Windows.

Create a Default VPC

  1. Navigate to VPC in the AWS console.
  2. Click Your VPCs.
  3. Click Actions and then Create Default VPC.
  4. Click Create.
  5. Click Close.

Create an EC2 Instance

  1. Navigate to the EC2 dashboard, and click Launch Instance.

  2. On the AMI page, select the Amazon Linux 2 AMI.

  3. Click on the checkbox next to t3.micro to select it, and click Next: Configure Instance Details.

  4. On the Configure Instance Details- page:

    • Network: Leave default
    • Subnet: Leave no preference
    • Auto-assign Public IP: Enable
    • Tenancy: Shared
  5. Expand Advanced details, and paste the following into the user data box:

    #!/bin/bash
    yum update -y
    yum install -y httpd
    yum install -y wget
    chkconfig httpd on
    cd /var/www/html
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/index.html
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/catanimated.gif
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/rainbow.gif
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/penny.jpeg
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/roffle.jpeg
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/truffs.jpeg
    wget https://raw.githubusercontent.com/linuxacademy/content-aws-csa2019/master/lab_files/03_compute/creating_an_ec2_instance/winkie.jpeg
    service httpd start
  6. Click Next: Add Storage.

  7. Click Next: Add Tags.

  8. On the Add Storage page:

    • Volume: Leave default
    • Size (GiB): 8
    • Encryption: Not Encrypted
  9. On the Add Tags page, add the following tag:

    • Key: Name
    • Value: Cat-Hall-o-Fame
    • Instances: Leave checked
    • Volumes: Leave checked
  10. Click Next: Configure Security Group.

  11. On the Configure Security Group page, click Create a new security group, and set the following values:

    • Security group name: labSG
    • Description: labSG
  12. Click Add Rule, and set the following values:

    • Type: HTTP
    • Source: My IP
  13. Click Review and Launch, and then Launch.

  14. In the key pair dialog, select Create a new key pair.

  15. Give it a Key pair name of "ec2lab".

  16. Click Download Key Pair, and then Launch Instances.

  17. Click View Instances, and give it a few minutes to enter the running state.

Manage the EC2 Instance

  1. Once the instance is fully created, check the checkbox next to the instance called Cat-Hall-o-Fame.
  2. Ensure that the Description tab is selected.
  3. Locate the instance's public DNS (IPv4), and select the icon next to it to copy it to the clipboard.
  4. Paste it into a new tab to preview it, which should result in a functioning website.

Connect to the EC2 Instance

  1. On the Instances page, right-click on the instance and click Connect.
  2. Copy the chmod command listed in the dialog.
  3. Open a terminal session and change to your downloads folder.
  4. Run the chmod command to change the permissions on the key pair we downloaded earlier.
  5. Copy the ssh connection string, listed under Example, and paste it into the terminal window to connect to the instance.
  6. In the AWS console, note the IPv4 public IP of the instance.
  7. Right-click the instance, hover over Instance State, and select Reboot. Note if the IP changes.
  8. Right-click the instance, hover over Instance State, and select Stop. Note the IP.
  9. Right-click the instance, hover over Instance State, and select Start. Note the IP.
  10. Right-click the instance, hover over Instance State, and select Stop.
  11. Once it's stopped, right-click the instance, hover over Instance Settings, and select Change Instance Type.
  12. Change the instance type to t3.small, and click Apply.
  13. Right-click the instance, hover over Instance State, and select Start.

Conclusion

Congratulations on completing this lab!