3.1.3. Using Linux Instance

This lab shows how to create an Linux EC2 Instance using AWS Management Console.

Tasks


To complete this lab, perform the following tasks:

  1. Launch a Linux Instance
  2. Connect to Linux Instance
  3. Clean Up Linux Instance

Step 1: Launch an instance


In this lab, we will launch a Linux instance using the AWS Management Console.
Let’s start!

  1. We will go to the Amazon EC2 console at https://console.aws.amazon.com/ec2/

EC2 Dashboard

  1. To create an instance, click on Launch Instance.

Launch an Instance

  1. The Choose an Amazon Machine Image (AMI) page shows a list of Amazon Machine Images (AMIs), that serve as templates for your instance. Select an HVM version of Amazon Linux 2.

Select Linux AMI

  1. On the Choose an Instance Type page, you can select the hardware configuration of your instance. Select the t2.micro type.

Select Linux Instance Type

  1. Select Review and Launch to let the wizard automatically config other settings as default.
  2. On the Review Instance Launch page, under Security Groups, you’ll see that the wizard created and selected a security group for you. You can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:
    1. Choose Edit security groups.
    2. On the Configure Security Group page, ensure that Select an existing security group is selected.
    3. Select your security group from the list of existing security groups, and then choose Review and Launch.
  3. On the Review Instance Launch page, choose Launch.

Review and Launch Instance

  1. When prompted for a key pair, select Choose an existing key pair, then select the key pair that you created when getting set up.
    Alternatively, you can create a new key pair. Select Create a new key pair, enter a name for the key pair, and then choose Download Key Pair. This is the only chance for you to save the private key file, so be sure to download it. Save the private key file in a safe place. You’ll need to provide the name of your key pair when you launch an instance and the corresponding private key each time you connect to the instance.

Warning: Don't select the Proceed without a key pair option. If you launch your instance without a key pair, then you can't connect to it.

Create Keypair for Instance

  1. When you are ready, select the acknowledgement check box, and then choose Launch Instances.
  2. A confirmation page lets you know that your instance is launching. Choose View Instances to close the confirmation page and return to the console.

Successfully Launch Instance

  1. On the Instances screen, you can view the status of the launch. It takes a short time for an instance to launch. When you launch an instance, its initial state is pending. After the instance starts, its state changes to running and it receives a public DNS name. (If the Public DNS (IPv4) column is hidden, choose Show/Hide Columns (the gear-shaped icon) in the top right corner of the page and then select Public DNS (IPv4).)
  2. It can take a few minutes for the instance to be ready so that you can connect to it. Check that your instance has passed its status checks; you can view this information in the Status Checks column.

Linux Instance Information

Step 2: Connect to your instance


There are several ways to connect to your Linux instance.
In this lab, we will try to connect to Linux instance by using PuTTY on Windows.

Connect to Linux instance by PuTTY on Windows


  1. Select the instance in Instance list then go to Actions > Connect

Connect to Instance

  1. Then in Connect to your instance dialog box, note the Public DNS information. (Here is ec2-18-162-209-38.ap-east-1.compute.amazonaws.com)

Linux Instance Connect Information

  1. Open PuTTYGen to convert the keypair download when creating the instance (in .pem or .bib format) to .ppk format.
    1. In PuTTYGen, click Load to select the Key Pair downloaded. (If we can not see the file, please change the File type in Open dialog to All File (*.*))

Load Created Keypair

  1. Choose Save private key to save Key pair to .ppk format.

Save Private Key

  1. Open PuTTY to connect to Linux instance:
    1. The Host Name should be ec2-user@<Public DNS> (List of username can be found in General prerequisites for connecting to your instance)
    2. In PuTTY, navigate to Connection > SSH > Auth then select the converted private key.
    3. Finally, click Open to connect to instance

Connect to Linux Instance

  1. If a dialog display about PuTTY Security Alert, click on Yes to accept the host key, put it to cache and continue to connect.

Successfully Connect to Linux Instance

Step 3: Clean up Linux instance


It will be the same as terminate a Windows Instance. For more details step, you can return to Clean up Windows instance

To terminate your instance


  1. In the navigation pane, choose Instances. In the list of instances, select the instance.
  2. Choose Actions > Instance State > Terminate.
  3. Choose Yes, Terminate when prompted for confirmation.

Amazon EC2 shuts down and terminates your instance. After your instance is terminated, it remains visible on the console for a short while, and then the entry is deleted.