How to remotely SSH (connect) Visual Studio Code to AWS EC2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
most of the code development by data Engineers data scientists or even machine learning Engineers are done in the cloud and we know that text editors such as Vim or Nano are not easy to use for code development therefore today I will be showing you how you can remotely connect your Visual Studio code from your local machine that's your computer your computer to your Cloud instance using SSH and in this case we will be using AWS ec2 instance as our remote server okay now if you have not subscribed to this channel I highly encourage you to do so right now and also click on the Bell so that you can get notified whenever we release any of our videos okay now the next thing you need to do now right now is go on Google and search for visual studio code and then you see this result that it gives you if you click on download because you need your Visual Studio code first if you don't have it yet now when you click on download it's going to give you different downloads based on the operating system so if you are using Windows you click this using Mac you know and what have you okay now when you click this when you click that then you can download and install the visual studio code now after you have done that the next thing is that you need an account since what we are trying to do here is we want to connect remotely connect your local machine to an a an AWS ec2 instance that means you need to create an account on AWS so if you go to AWS dot amazon.com then you can sign up for for an account okay now after you have signed up like in my case I already have an account so after you have signed up if you come right here you can search for ec2 when you come right here you search for ec2 then you can see ec2 right here then if I click on this ec2 now what we want to do right here is we want to launch an instance an instance of ec2 we want to create an Institute that we are going to be connecting to so all you have to do is come right here launch instance so if you click launch instance okay now we need to give this a name okay in this case I want to give it this name I want to give it YouTube remote connects so I give it YouTube remote connect okay and then you have to select what uh operating system that you want to use right here which operator you as you can see application and operating system images that's the Amazon machine image so in this case we want to select Ubuntu okay now also which of that do you want to do you want to select right here if you see you can see that we have several right here however there are we have a free free uh free ones right here so you don't have things what we are doing is just light things we are trying to do right here we are just trying to see how we can connect remotely connect our local machine to uh to our ec2 instance therefore just go with the free the free tier because we are eligible for that so I will select that okay so if I select that this one just leave this one right here this architecture and then you have to select which instance type if you also click on this drop down you can see if you scroll down if you scroll down you see that we have a free tier elegy which is this T2 micro micro which is okay for what we want to do okay now the next thing is a key pair okay so in this case I would like to create a key pair so right here we are also going to create a key pair okay so do so for me if you look at this I already have different KPS that I've created but in this case I'm I could select one of them but in this case let me create a new one so you guys can see so if I create this okay and I've been asked to give it a name I can give it this name testing remote connects I can say testing remote connect okay you can see that and then in that case I can let it so this is going to be selected PM dot PM okay and then do create key pair so when you create keep here you see something happen right here it's downloaded a pen file for me if I open that folder you can see there is a pen file VM file right here testing remote connect okay so in my case I will just leave it in the downloads folder if you want you can take it to a different folder you know you can create a separate folder or whatever folder you want to put it but in this case I will just leave it in the downloads folder okay and then I'll come right here I will create Security Group so just for the sake of this video I can do I will just select only this one because I only want to SSH into the ec2 but supposing I want to connect to my IC to Via https or HTTP then I would check this but in this case I just want to SSH I can just you know just use this okay and in this case also you could select where you want to where you want to connect from is it anywhere or maybe my IP if you click on this drop down you'll see uh different options but in this case I will leave it as anywhere okay this configuration storage I will leave this right here and then I'll leave every other thing then I will say launch instance so now as you can see this is creating uh the instance the ec2 instance for me right here then I can click this I can click this instances or you can even click this to go to that instance but in this case I can just click instances so that I can see all my all my ec2 instance okay now this is the one we just created a YouTube remote connect right as you can see it says it says running right if I refresh my browser you can see that this is it it says running and it is initializing okay now we have been able to provision for ourselves and ec2 instance on AWS Cloud okay now let us see if we can connect to this using our command line before we then use Visual Studio code to to connect to this okay so let's just just for us to be sure that this is running I would go to my computer then I will look I'll bring out my command prompt so if I bring my command prompt from my other computer right here you can see I have this right here okay now if I want to connect to this what I will first of all do is this I'll select this if I select this then I'll go to connect I'll go to connect then it's going to bring me right here now this is the line of code that I need to connect you can see I have SSH minus one testing this is the name of that key that remember that uh that pen key that was created that was downloaded that I put in my down that I left in my downloads folder which is which is this right here you can see that okay now then Ubuntu Ubuntu since the operating system that we selected here is Ubuntu if you remember the Amazon machine image that we selected was Ubuntu so that is what the user right here is Ubuntu so now what what do we need to do now what I need to do now is I'll come to my command line and then I will navigate to my downloads folder if I navigate to my downloads folder and why am I down why am I going to my downloads folder because that is where I have the the pen key that's why I left it so if I copy this click on this to copy and then I'll come back to this then I will paste now you can see that I've pasted and then I can do enter now this is asking me if I want to continue I'll say yes and then you can see that it's trying to connect now you can see that this has connected you can see that guys this has connected so that this tells us that we are able to connect using our command line to our uh to our ec2 instance do we have anything there if I do LS see if I do a less there is nothing there we don't have anything there right now however let us create let us create a folder I'll say make directory and then I will say YouTube underscore learning I'm creating a directory that's a folder if I create that that has created let us use LS to check you can see that guys let me make this if I can make this bigger for you okay very good you can see now that I've created a folder now let me CD into that folder see the YouTube underscore learning if I do this you can see I have YouTube underscore learning right let me create a file inside that so if I create if I can say touch uh I can say test underscore ETL dot py so I'm creating a python folder right there so I do enter right now let us check do I have something right there in my Youtube Learning folder let's do LS very good you can see that we have this right here right now you can see that right here guys so let's assume you want to write something into this uh into this folder right then you have to probably use Vim or Nano and that's when I'll say Nano I can say Nano test let me put tab to complete it that's not noticed underscore hdl.py if I do enter you can see right here guys that this is no no this is a text editor that I can use to start typing whatever thing I want to do but it is pretty much not easy to be working with Nano or vin right and that is why I want to show you how you can use your Visual Studio code to connect and one of that thing also is that using your Visual Studio code on your local machine helps you to be able to transfer files from and to your ec2 instance okay which I'm going to show you right here you can also download files directly from that so right here now I'm going to close this I'm going to do Ctrl X to close that so now on our ec2 instance we have been able to create a folder which is called or a direct which is called YouTube underscore learning right and also we have also been able to create a DOT py file which is test underscore ATM okay now let us now see how can we use Visual Studio code to connect to these uh ec2 instance to do that I will go to my computer and then I will look for the visual studio code that I have already installed then I will do I'll click that Visual Studio code okay now that I've clicked that one thing you need to first of all do is come to this extension click extension so when you click the extension you then you search for remotes SSH if you do that you see this first one that comes up remote Dash SSH you see the most remote does SSH then I'll do install I will install that you can see that this is installing and this has finished installing now I've gotten the remote SSH extension into my visual studio code then the next thing I'm going to do is I'll come right here you can see this right here it says open a remote window okay then I'll click this when I click this then I can come right here and say connect connect to host if I click connect to host you say connect to host now is is giving me different options right here right and this is because I already have different ec2 instances right here that which I've already created previously but for the sake of you guys that you are doing this new all you have to do is you say configure SSH hosts so if I configure because right now you want to configure a new one right so you do configure SSH hosts if I click that now it is asking me that where that you should select the configuration file to update right then you can select this first one users then this is your username for your computer so you click that when you click that it brings you right here as you can see that in my own case I already have different uh different users right a different host that I'm connecting to okay then your case if you do if you don't have anything right here then you have to then create so what you can just do is then you can say host so if you say host what is the OS what is those that we are talking about right here if you go back to your ec2 instance if you go back to your ec2 instance I'll go back to mine you can see this is the host this is the name of my uh ec2 instance I would copy that I'll copy that then I'll go to my vs code I'll put that in okay and then I'll come right here remember you this needs to be indented the way it is right here then I'll say host name you say the way it is written right here host name so what is the host name so for the host name go back to your to your uh uh easy to instance and then you look at this public ID address you can see this public ID address right here let me make it that big this public iPad and copy that okay copy that then you would paste that right here and then you have user what is the user what is the user of your ec2 instance remember I told you previously that because you created this with Ubuntu that means your user is uh is Ubuntu okay so all you have to just do is you just put to Ubuntu you can see your platform is Ubuntu so all you have to just do is on this then you can just say [Music] Ubuntu okay now the next thing is what is called file name take note you need to type it the way it is right here your file name that file name is the pen file that we downloaded before that pen file and remember that that pem file is I put it right here in my downloads folder okay so what I need to do is I need to copy the path of this spam folder so I'm using a Windows uh a computer so I can press shift down and then right click to copy the path copy as path I'll copy that if you are using a different system yeah you need to look for a way to do that but also also you could even type it out you could just copy this and then type out the name of this right so in my case I will just do this I will remove these quotes I'll remove this code now you can see now I have the host I have the host name I have the user and I have the identity file the identity file is this uh this pen file this peak this uh PA key that we have downloaded before okay then I will save this okay now that I have saved this okay now I can come back to this place this open a remote window and then I can click that again and then I can say because we have configured it right now then I can say connect to hosts if I connect to you can see right here now guys that the name of that ec2 instance that cloud instance that I have you can see that that has that is showing right here now YouTube remote connect I will click this now you see it's asking me that select the platform of the remote hosts YouTube remote connect that's the easy to instance the platform of that is the Linux platform I can come back here and show you if you look at this if you look at this when if you click if you click or you check on this your ec2 you can see it's a platform Ubuntu platform details Linux you can see Linux so in that case I will just come right here and I'll select Linux and you can see it's trying to connect open remote it's doing opening remotes so it's trying to connect now very good you can see this has changed SSH YouTube remote connect let me make this bigger you can see we have that right here that that is how you can connect to your remote server from your local machine now how do we also verify that let us see Let Us open a new terminal if I open a new terminal you can see this is Ubuntu this is right here guys this is right here I've been able to connect and this will make your code development to be much more easier you don't have to use Vim or Nano so if I do in LS you can see remember remember we had created using the command line remember we had created these uh this folder and this file name testetl dot py you can see right here Youtube Learning if I CD into YouTube if I type you and I press tab you can see I I I navigated into that if I do LS you can see I have my testetl DOT py also I could go into that into those folders if we come to file then say open folder open folder you see it is asking me right here that om Ubuntu is asking me which folder I want to come in I want to come into YouTube learning if I say YouTube learning and I will say okay now you can see it's asking me do I trust the authors of all the files I will say yes I trust all the authors now you can see that right from my local machine I've been able to connect to that folder that directory that I created earlier and then I have my file right here you can see my DOT py file which I can say prints I can just say maybe print this I can say this is just a test if I say this is just a test and I save it and maybe I want to run it I can just say I can just go to my terminal and then I can since I'm in this folder I can say python test etl.py enter okay save command python not found did you mean okay I think he wants me to use Python 3 so I can say python I can say python Python 3 10.tp wire enter you can see it has printed that for me this is just a test this is how you can do things right here guys it shows you know it's going to make your development easy and fast and also if you look at this if I if I right click this I could download you can see if I Do download it's going to download to my from that ec2 instance from that cloud computer to my personal computer right if I Do download you see is asking where do I want to download so that means I can download it to my downloads folder or any phone or any folder on my computer if I do this download you see let us check you see it has downloaded on my downloads computer okay the same thing applies to if you want to if you want to transfer uh a for a file if you want to transfer a file from your personal computer into that remote server it's pretty much easy like let's say this credentials.txt I can just drag it put it right you see it is right there immediately right I have this credentials I have this I have that you can see if I want to remove it I can easily just you know delete this is how you can be moving stuff now you can see that we have been able to have been able to show you how you can remotely connect to your ec2 instance by using SSH and I've showed you how you can even download a file that you already have in your easy to install to your local machine and also even to be able to drag a new file into your ec2 instance seamlessly you can also create directory create file here you can create new folder here pretty much it is easy and that is how you can make life easier for yourself whenever you are doing any code development that involves you developing in the cloud I hope you guys get this right now guys and if you are new on this channel I highly encourage you to subscribe to this Channel and click on the bell for uh for notification whenever I will release any of our video videos and don't forget to like share and also share our videos so that more people can benefit and if there's anything you also like me even to to explain or to teach more please put that in the description uh in the comment section below thank you guys see you in the next video bye
Info
Channel: tuplespectra
Views: 10,822
Rating: undefined out of 5
Keywords:
Id: sQQjMnEkGjs
Channel Id: undefined
Length: 23min 7sec (1387 seconds)
Published: Sat Jun 03 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.