Deploying VSCode on EC2 and access it from your local VSCode

Create your Key Pair

If you already have a key pair, you can skip to the next step.

First, you need to enter the EC2 Console. On the left navigator bar, choose Key Pairs. On the Key Pairs interface, choose Create Key Pair.

On Create Key Pair:

  • At Name, enter any name for your key pair.
  • Next, choose a key type and the .pem format.
  • Click Create key pair at the bottom to proceed to create your key pair.

Save your private key in your local computer and use it later for the lab stack creation.

Ensure that only you can access the .pem file.

  • On Linux, use the following command:
chmod 400 <đường dẫn tới file pem>
  • On Windows, ensure the file access permission is as follow:

Create your CloudFormation Stack

Dowload the template here.

Enter the CloudFormation console.

  • Choose Create Stack.

Enter **Stack Name**s.

At SshKeyName, enter the newly created Key Pair (from the previous step).

Click Next through all steps and wait for the stack to complete.

Configure SSH connection on your computer

On the CloudFormation Stack UI, get to Output. Find the key IdeInstancePublicIP, the value is the address of your VSCode server instance.

Add the following lines C:\Users\<username>\.ssh\config (on Windows) hoặc ~/.ssh/config (on Linux):

Host remote-connection
    HostName <EC2 public ip>
    User ec2-user
    IdentityFile "<path-to-pem>"

Connect your VSCode with your EC2 Instance

  • Install the Remote-SSH addon for your local VSCode

  • After installing you’ll see the icon on the lower left corner of the screen

  • Click the icon to open the Connection command pallete. Choose “Connect to Host…”

  • Choose “Add New SSH Host”

  • Choose your config file

  • After configuring, click the icon to open the pallette and choose “remote-connection”

Next, choose Platform details “Linux”, then “Continue”

Choose “File > Open” to open your environment folder

Choose the folder /home/< username >/environment