Connecting to EC2 Instance from VSCode

Connecting via SSH from Visual Studio Code to an EC2 Instance is a quick alternative to using Cloud9.

1. Download Visual Studio Code and the Remote - SSH extension

You can download VS Code here: Download VSCode

Once downloaded, install the Remote - SSH extension.

image.png

2. After installation, click the icon in the bottom left corner to open a dialog box.

image.png

3. Click on Connect to Host.

image.png

4. Click on Add New SSH Host.

image.png

5. In the input box, enter deploy-instance-remote and press Enter.

image.png

image.png

image.png

7. In the SSH configuration block, replace the placeholder with the correct IPv4 address of the EC2 Instance and the path to your Key Pair on your machine.
Host deploy-instance-remote
  HostName 3.106.228.72
  User ubuntu
  IdentityFile "C:\Users\ADMIN\Downloads\devsecops-kp.pem"

image.png

8. Click the SSH icon in the bottom left corner to start the Connect process.

image.png

9. When a new window appears, select Continue.

image.png

10. Click on Linux and wait a moment for the VSCode Server to be installed on the EC2 Instance.

image.png

11. Select Open Folder and click OK.

image.png

12. This is the interface after connecting.

image.png