Test Connection

Checking the Connection

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

  1. Download Visual Studio Code

Create VPC

  1. Go to the EC2 page
    • Select Instances from the left navigation menu
    • Select the EC2 Public instance
    • Select Connect

Create VPC

  1. In the Connect to instance panel
    • Select the SSH Client tab
    • Copy the SSH command from the Example section
    • Note: you’ll need to replace the path to your key pair file

Create VPC

  1. In Visual Studio Code
    • Open Extensions (Ctrl+Shift+X)
    • Search for and install the Remote - SSH extension
    • This extension lets you connect via SSH directly from VS Code

Create VPC

  1. Connect via SSH from Visual Studio Code
    • Open a terminal in VS Code (Ctrl+`)
    • Navigate to the folder that holds your key pair file:
    cd /path/to/your/keypair/folder
    
    • Run the SSH command (replace <public-ip> with the Public IPv4 address of EC2 Public):
    ssh -i "aws-keypair.pem" ec2-user@<public-ip>
    

Create VPC

  1. Check the internet connection on EC2 Public
    • Once the SSH connection succeeds, run a ping command:
    ping 8.8.8.8 -c5
    
    • You should see responses confirming EC2 Public has internet connectivity

Create VPC

Connect to the EC2 Private Server and Check Its Internet Connection

  1. Get the private IP of EC2 Private
    • Go to the EC2 console
    • Select Instances
    • Select EC2 Private
    • In the Details tab, note the Private IPv4 address

Create VPC

  1. Test connectivity from EC2 Public to EC2 Private
    • From the terminal already connected via SSH to EC2 Public
    • Run a ping to the private IP of EC2 Private:
    ping <EC2-Private-Private-IP> -c5
    
    • A successful result confirms network connectivity between the two instances

Create VPC

Create VPC

💡 Preparing to SSH into EC2 Private

  1. Download the tools needed to transfer the key pair
    • EC2 Private has no public IP, so we can’t SSH into it directly from our own machine
    • We need to copy the key pair file to EC2 Public so we can SSH from there into EC2 Private
    • Download the following tools into the same folder as your key pair:
  1. Convert the key pair to PPK format
    • Run puttygen.exe
    • Click Load

Create VPC

  1. Load the PEM file and convert it
    • Select the aws-keypair.pem file
    • Click OK on the success message
    • Click Save private key
    • Save it as aws-keypair.ppk

Create VPC

  1. Finish converting the key
    • Confirm that aws-keypair.ppk has been created
    • This file will be used with PSCP

Create VPC Create VPC Create VPC

  1. Upload the key pair to EC2 Public
    • Open Command Prompt (Windows) or Terminal (Mac/Linux)
    • Navigate to the folder containing PSCP and the key pair
    • Run the following command (replace <EC2-PUBLIC-IP> with the public IP of EC2 Public):
    pscp -i aws-keypair.ppk aws-keypair.pem ec2-user@<EC2-PUBLIC-IP>:/home/ec2-user/
    

Create VPC

  1. Get the public IP of EC2 Public
    • Go to the EC2 console
    • Select the EC2 Public instance
    • In the Details tab, copy the Public IPv4 address

Create VPC

Create VPC

  1. Confirm the file was uploaded
    • Go back to the SSH terminal connected to EC2 Public
    • Run ls to list files:
    ls
    
    • You should see the aws-keypair.pem file in the folder

Create VPC

  1. Set permissions on the key pair file
    • AWS requires the key pair file to have restricted permissions
    • Run:
    chmod 400 aws-keypair.pem
    
    • This ensures only the owner has read access to the file

Create VPC

  1. SSH into EC2 Private from EC2 Public
    • Use the private IP of EC2 Private:
    ssh -i aws-keypair.pem ec2-user@<EC2-Private-Private-IP>
    
    • Type yes when prompted about the fingerprint
    • You’ve now successfully connected to EC2 Private!

Create VPC

  1. Check the internet connection from EC2 Private
    • Try pinging out to the internet:
    ping 8.8.8.8 -c5
    
    • ⚠️ Result: The ping will FAIL because EC2 Private doesn’t have a NAT Gateway yet
    • In the next step, we’ll create a NAT Gateway so EC2 Private can access the internet

Create VPC

💡 Connection Architecture Summary:

  • Your computer → SSH → EC2 Public (via public IP)
  • EC2 Public → SSH → EC2 Private (via private IP)
  • EC2 Private → ❌ Internet (no NAT Gateway yet)