Create and Work with an EC2 Instance in AWS

45 minutes
  • 3 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Default VPC
  1. Navigate to VPC > Your VPCs.
  2. Select Actions > Create default VPC.
  3. Click Create default VPC.
Create an EC2 Instance
  1. Navigate to EC2 > Instances.

  2. Click Launch instance.

  3. On the AMI page, select the Amazon Linux 2 AMI.
    1.Set the instance type as a t3.small selected, and click Next: Configure Instance Details.

  4. On the Configure Instance Details page:

    • Network: default
    • Subnet: No preference
    • Auto-assign Public IP: Enable
  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 curl
    chkconfig httpd on
    service httpd start
  6. Click Next: Add Storage, and then click Next: Add Tags.

  7. On the Add Tags page, select Add Tag then add the following:

    • Key: Name
    • Value: Webserver
  8. Click Next: Configure Security Group.

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

    • Security group name: LabSG
    • Description: LabSG
  10. Click Add Rule, and set the following values (leave the default SSH rule):

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

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

  13. Give it a Key pair name of "Lab".

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

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

Manage the EC2 Instance

Once the instance is running with 2/2 status checks:

  1. Copy the instance’s public DNS (IPv4), and paste it into a new browser tab.
  2. On the EC2 instances console, right-click the instance, and select Connect.
  3. In the terminal, change to your downloads directory (e.g., cd Downloads).
  4. Run chmod 400 Lab.pem to adjust the permissions on the file.
  5. Connect to the instance using the ssh command provided in the dialog when you click Connect (or using the PuTTY instructions).
  6. Note the IPv4 public IP of the instance.
  7. With the instance selected, click Actions > Instance State > Reboot.
    • Does the IP change?
  8. Click Actions > Instance State > Stop.
  9. After it’s stopped, click Actions > Instance State > Start.
    • Does the IP change?
  10. Click Actions > Instance State > Stop.
  11. Once it’s stopped, click Actions > Instance Settings > Change Instance Type.
  12. Change the instance type to t3.small, and click Apply.

Additional Resources

You have been asked to create a basic web server for your group on a default VPC. To do this, you will need to create an EC2 instance.

Once you have created this instance, you will need to log in to it to make sure it can be accessed.

Later, you may be asked asked to change the machine type of the EC2 instance because it needs more resources. You need to do this without losing the EC2 instance (but you may stop it).


Log in to the live AWS environment using the credentials provided, and make sure you are in us-east-1 throughout the lab.

When entering the instance user data, use the following:

#!/bin/bash
yum update -y
yum install -y httpd
yum install -y curl
chkconfig httpd on
service httpd start

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

Windows users can also use WSL2 on how to connect to EC2 using WSL2 on Windows (Recommended)

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?