Test Connection

Checking Connection

There are several ways to connect to EC2 instances. You can follow the instructions to connect to EC2 using PuTTY. In this lab, we will use Visual Studio Code to establish the connection.

  1. Download Visual Studio Code

    Create VPC

  2. Access the EC2 page

    • Select Instances
    • Select EC2 Public
    • Select Connect

    Create VPC

  3. In the Connect section

    • Select SSH Client
    • Copy the code in the Example section

    Create VPC

  4. In the Visual Studio Code interface

    • Download SSH

    Create VPC

  5. In the Visual Studio Code search bar

    • Follow the instructions to connect via SSH

    Create VPC

    Create VPC

    Create VPC

  6. Configure SSH.

    • Paste the copied path from EC2 Public here
    • Edit the key pair path to point to the correct file location
    • Save the file

    Create VPC

  7. Connect via SSH.

    • Re-run the commands in the search bar as shown above
    • Search for and select the IP public EC2 to connect

    Create VPC

    Create VPC

  8. Test the internet connection of EC2 Public by running the command:

    ping amazon.com -c5
    

    Create VPC

Connect to the EC2 Private Server and Check Internet Connection

  1. Access to EC2

    • Select Instances
    • Select EC2 Private
    • Select Details
    • Select Private IPv4 addresses
    • Then connect SSH to EC2 Public

    Create VPC

  2. Perform a ping test to the EC2 Private’s private IP address to test the connection from the EC2 Public server to the EC2 Private server. Use the following command:

ping <IP Private EC2 Private> -c5

Create VPC

  1. EC2 Private will not have a public IP address because we are not assigning this server a public IP. To be able to ssh into EC2 Private, we will make an ssh connection from EC2 Public through EC2 Private private IP address

    • Download the pscp tool to the same folder containing the aws-keypair.ppk file to copy the aws-keypair.pem file from our computer to EC2 Public .

You download an RSA and DSA key generation utility as puttygen.exe

  1. We use puttygen.exe to generate key

    • Select Load

Create VPC

  1. Select aws-keypair.pem

    • Select OK
    • Select Save private key with the name aws-keypair.ppk

Create VPC

  1. Complete the generation key

Create VPC

  1. Launch Command Prompt. Change the path to the folder you just downloaded pscp. Run the command below to upload the aws-keypair.pem file to the /home/ec2-user/ directory of the EC2 Public server.

    • You will need to replace the public IP address of EC2 Public parameter before running the command.
pscp -i aws-keypair.ppk aws-keypair.pem ec2-user@<EC2 PUBLIC public IP address>:/home/ec2-user/

Create VPC

  1. Access to EC2

    • Select Instances
    • Select EC2 Public
    • Select Details
    • View Public IPv4 address

Create VPC

  1. Return to the EC2 connection interface. Make sure you copy the aws-keypair.pem file to the EC2 Public server, we execute the command
ls

Create VPC

  1. Update the permissions for the aws-keypair.pem file by running the chmod 400 aws-keypair.pem command. AWS requires the key pair file to be restricted before it can be used to connect to the EC2 server.
chmod 400 aws-keypair.pem

Create VPC

  1. SSH to EC2 Private server
ssh -i aws-keypair.pem ec2-user@<EC2 Private server's private IP address>

Create VPC

  1. Perform ping test to amazon.com. As you can see, we cannot connect internet from EC2 Private. In the next step, we will create NAT Gateway to allow the EC2 Private server to connect to the internet in the outbound direction. Keep the connection to EC2 Private so that we can check the connection to internet after finishing creating and configuring NAT Gateway.
ping amazon.com

Create VPC