How to do remote development with Visual Studio Code on AWS EC2 via SSH

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] Hello everyone, I'm Chirag, and welcome to this  video. In this video, I will cover how to do remote   development using Visual Studio Code and EC2  For instance while you are working on a big data   engineering project or a data science project you  will need the hardware which is compute or memory   optimized you will need GPUs for model training  depending on the type of the project. Now, most   of the time such Hardware or configuration will  not be available as a part of your local system   So for that reason, one can go for cloud computing  or any on-premise virtual machine setup within   the organization. However in both the scenarios you  will take remote access to the VMs for development   now as a part of this video we will consider  Amazon EC2 as our remote virtual machine where   we want to do the development. Now suppose we  have an EC2 instance with Ubuntu or Linux as   an operating system where we want to do the  development and here as we know that we do   not get any user interface or IDE setup to  do the project development smoothly. And it   will be really hard to use text editors  like Vim or Nano for project development   Now to solve this problem we can connect the  IDE and in this case, it's going to be the Visual   Studio Code from the local machine to the remote  instance for development via SSH on Port 22.   So, as a part of this video, this is what a  we will set up now before we go ahead and   set this up please make sure that you have Visual  Studio Code installed. As a Next Step let's launch   a dummy ec2 instance that will act as the  remote server for the purpose of this video   so let's navigate to the AWS Management Console and  then let's navigate to EC2 Management console   now once you are within EC2 Management Console  Click on launch instance as a part of this we need   to enter few details to successfully launch an EC2  instance, first is the name so I will say remote dev server as a part of the AMI we are  going to select Ubuntu and from this drop   down we will select Ubuntu server 22.04 and  then we will leave rest of the option as it   is with an instance type for the purpose of  this video I am going to select t2.micro   as a part of the key pair, I am going to select the  existing key pair but you can go ahead and create   a new key pair if you don't have the existing  one so in my case I am going to select remote   -dev and I have this PEM file locally  now as a part of the network settings we are   going to select create a new security group and  we will make sure that this option is checked   that is Allow SSH traffic from anywhere now here  from this drop-down, you can also select My IP or   you can restrict the access to your particular  IP address but for now I will select anywhere   Within storage, we will keep it as 8 Gb  and then we will click on the launch instance   we have successfully launched the EC2 instance and  now it is in running state so I will quickly SSH   into that instance just to check that I am able to  connect to that instance so for that I am going to   copy this public ipv4 address and then I will  open a terminal and the command is SSH -i   -i followed by the identity file so in my case  it's in the downloads directory with the name   that is the remote-dev.pem followed  by the username now since we have launched   the EC2 instance with the Ubuntu operating  system the default username would be Ubuntu   @ paste the ipv4 address  that we have just copied and say enter type in yes now here as you can see we have  successfully logged in into the   EC2 instance that we have just launched  okay here we will create a directory I will say mkdir remote-work and within  that directory I will create one file that is main.py now we will close  this connection I will say exit  okay now since we have successfully launched  the EC2 instance we are going to open the   Visual Studio Code so here it is and once you  are within Visual Studio code we are going to   install the extension so to install the extension  Click on this extension icon and search for SSH and as soon as you search for SSH it  will display the results in this panel   so we have to select this first option  or the first extension that is the remote   remote-SSH and the provider is Microsoft  and click on that and click on install now here we have installed this extension  successfully now as a Next Step you should   be able to see this green icon on the bottom left  corner okay so as the next step we are going to   click on that which says open a remote window now  as soon as you click on that icon it will display   a couple of options now here the first step is to  configure the SSH file or the SSH configuration   file so for that we are going to select the third  option that is open SSH configuration file and   here in my case I will select this first file that  is user/srcecde/.ssh/config so I am going to   click on that and it will open a config file for  us now if you are setting this up for the first   time this file might be empty for you so let's  make sure that it's empty as of now and we will   start from the beginning so here we need to Define  couple of options so the first option is that we   need to define the Host followed by the Alias name  that we want to give so I will simply say remote Dev or I will say remote-vm okay now  once you Define alias you need to   define the hostname you need to define  the user and then you need to provide   the path of your identity file so the first  thing that you need to Define is HostName   So within HostName it's going to be your IPv4  public IP address of your EC2 instance so   in my case it's this one followed by the user  with which we want to login now since we have   launched the Ubuntu operating system as a part  of that VM the default username would be Ubuntu   followed by the IdentityFile now here you need  to provide the path of your identity file so in   my case it's /Downloads followed by  remote-dev.pem okay so here we   have successfully defined one host similarly you  can define multiple host as a part of this file   so let's define one more and here I will change  the Alias name to let's say prod-vm and   then you need to define the respective hostname  user and the identity file okay so this is how   you can Define multiple hosts as a part of the  SSH config file now once you are done with the   configuration or setting up your SSH config file  let's close this and after that click on this   green icon from the bottom left corner and now  here we are going to select the first option that   is connect to host because we want to initiate the  connection to our remote machine okay now as soon   as you click on that it will list out all the host  that you have defined as a part of your config   file now in my case I want to connect or I want to  do the remote development on this remote-vm   host so I'm going to select that and then it will  open a new window and as you can see it's opening   the remote connection over here you can see the  status okay let's maximize this so now as you   can see we have successfully connected our Visual  Studio code with the remote machine and now if you   can see the status on the bottom left corner so  it says SSH:remote-vm it means that   we are connected with the remote server that is  with the Alias name of remote-vm also as   a part of this terminal if I do "ls" then we should  be able to see the directory that we have created   as a first step that is remote-work and  if I do "ls" remote-work directory then we   should be able to see main.py now apart from this  if you click on this button that is open folder it   will list all the files and directories from the  remote host for the purpose of this video we are   going to open this remote-work directory  so I am going to select that and click on OK   click on yes I trust the authors now it has opened  the directory that is remote-work and   within that directory, we have this main.py that  we have created earlier now let's save this file   and let's open the terminal instance to execute  this file and we can say python3 main.py and it   should be able to execute on the remote machine  okay so guys this is how you can do the remote   development using Visual Studio Code and the EC2  instance or on any remote machine so guys that's   all I wanted to cover as a part of this video  until that time if you want me to do tutorial   on any use case or service then please leave them  below and I will try my best to come up with the   tutorial as soon as possible and if you have any  queries or comments then again please leave them   below and don't forget to like and subscribe  to my channel and see you next time [Music] thank you
Info
Channel: Srce Cde
Views: 34,696
Rating: undefined out of 5
Keywords: aws, amazon web services, ec2, ssh, vscode, visual studio code, remote development
Id: elkL1OF9fxI
Channel Id: undefined
Length: 9min 55sec (595 seconds)
Published: Mon Aug 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.