[0:00]Hello everyone, my name is Abhishek and welcome back to my channel. So today we are at day five and in this class we are going to learn about the efficient way of creating virtual machines, because in the previous classes we learned about what is a virtual machine, we looked at how to create virtual machines and we learned about the concept of virtual machines, right? So, if you haven't watched our previous videos, uh, like you know, day zero to day four, I would highly recommend you to go and back go back and watch those videos. All the videos are available in the DevOps playlist and then you can come back and watch this video. Uh, so for today, what we'll do is we will try to understand how to log into the virtual machine that we have created and what are the automated ways of creating these virtual machines. So if you followed our previous class, we talked about improving the efficiency by using the automation that is by using scripting, uh, you can automate your AWS uh, instance or the virtual machines uh, creation using either the AWS API, AWS CDK, AWS CLI, you can also use AWS Cloud formation templates and finally Terraform. So these are the different options that are available. So for today, what we'll start with is we'll start with login to the AWS EC2 instance because that is the first step that everybody has to understand. So to log into the AWS EC2 instance, there are two different ways. One is you can again go back uh to your AWS uh, you know, UI. So this is my AWS console. You can come to the AWS console and what you can do is you can go to the EC2 dashboard. In the EC2 dashboard, if you see if you watch carefully here, I have one instance that is running. So click on the instance that is running and then you have a option called AWS uh instance ID. Click on the instance ID, so there is an option here to click on connect. So once you click on connect, scroll down and again there is an option to connect. Once you do this, it will try to establish the connection with the IP address, like this is the IP address. I will delete this instance, so there is no problem in sharing this IP address, uh, as of now, because once the video recording is done, I would, uh, delete, uh, this virtual machine. So you see the connection is established and now I am connected to this virtual machine. So this virtual machine can be anywhere in the world. Currently this is in the North Virginia and I can make instructions to this virtual machine. Like, for example, I will show you creating a file. Okay? So what I can do is I can say touch and uh create a file called Abhishek and uh if I do LS, the file is created. So that means I'm able to log into this virtual machine and I can do any instructions with this virtual machine.
[2:43]So this is one way of doing things, right? So here I am doing it through the AWS uh, UI and uh, probably people are very convenient with their own terminals, or they might use some fancy terminals like Mobile Xterm, or they might use uh,
[3:26]no machine, or different types of uh, virtual machines, and they have their own packages like Bu Bo. So, avoid this thing and I'll show you how to install uh, a terminal in your personal laptop and connect to this virtual machine. Okay? So now I'll go back because I don't want this connection. I can simply click on the close button and my AWS connection that I have established through the UI is cancelled. So to connect through your terminal, firstly, you have to have a terminal in your laptop. Okay? So it depends on which laptop you are using. For example, if you are on Mac, uh, there is a terminal called I term. Okay? This is I terminal, that is called I term. So, I term is the best one that I would prefer for users who are using Mac. Okay? So just come here, uh, click on the I term and you can simply download. Okay, it hardly takes you one minute to download and install. I personally use I term and I find it much better than the other options that are available. But if you have Windows, you have a wide range of options uh that are available, because uh, the default terminal that comes with the Windows, that is the uh command prompt is not so uh user friendly. So always go with the other things, like, you know, you have Putty. Putty is something that is widely used. Uh, click on Putty and uh, you have an option to download Putty. So, click on the download Putty and the user interface is not so great compared to the other options. So if you want a better user interface, you can also go for Mobile Xterm. Okay? So mobile Xterm is uh, another, uh, terminal that you can use on any platform. So here you have option for like using Mobile Xterm, you can uh, save your uh, password and uh, you can authenticate, uh, with 10 virtual machines easily, if you're using a free account. And if you have a paid version of Mobile Xterm, you can go up to 100 or 1000 virtual machines. I don't remember exactly.
[5:50]So, these are all, uh, you know, not so, uh, important things. You can use any uh browser or you can uh sorry, any terminal that you are interested in. So, this is a terminal that I have at this point of time. Uh, let me, uh, share that with you. Okay?
[6:09]So this is the terminal, uh, that I'm using and uh let me, uh, increase the font of it.
[6:17]Perfect. I think it looks good to you. Now, how do I log in to this virtual machine from my terminal? I'll show you. Okay? So come here, if you scroll down, so again, I came to the EC2 dashboard. This is the instances, I clicked on the instance button that I required. And now, always go with the public IP address. Okay? So the private IP address is only accessed within the AWS network. So within your VPC or within the, it depends on your AWS configuration, but understand this as a closed IP network. Okay? So, if you want to connect, uh, from your laptop or from any external sources, what you need to do is you have to pick up this IP address, that is the public IP address. Okay? And the, by default, we have created a Ubuntu machine. Already, I think people already know it, uh, from our previous videos. So what you will do is SSH Ubuntu at the rate the IP address that we saved. Now, as you click on enter, it will for the first, very first time it would ask you, do you want to remember the fingerprint? Always mention yes, and once you do this, the connection would be denied. I know, uh, it would be denied, but I would I just wanted to show you the reason why the permission is denied is because you have not provided the key value pair. If you remember the previous class, I mentioned that you have to provide the key value pair while you log in, because key value pair is a way that you authenticate to your AWS virtual machine. So, how do you do that? SSH minus I. I stands for the identify file. And I know where my identify file is. I stored my identify file in a specific location that I'm aware. Uh, sorry, if you wanted to, uh, modify the location, you can also modify and you can, uh, store that in your, uh, downloads, uh, desktop, any, any location that you want. Personally, I just saved it in the, uh, downloads location. So I called it test 111 PM, and, uh, followed by Ubuntu at the rate the same IP address that I have previously provided. Now, again, if you click on the enter, this would fail one more time, saying that the permissions that you have provided are too open. So what is the reason for saying the permissions are too open? Okay. So PM file is basically a secret file, or, you know, it has sensitive information. So, in your case, your virtual machine, uh, personally now we are logging into your laptop, okay? But sometimes what happens is your resources might be shared, okay? So, as a DevOps engineer, you might work from different, uh, resources. So, let's say you're using a shared virtual machine, or you're using a shared physical server from where you want to log into AWS. So, PM file does not allow you to keep the permissions open because this is my personal PM file, right? This is PM file for Abhishek Vimalav, or my AWS account. So, if this is open, somebody else can access this PM file and log into your machine. So, always keep the permissions closed. So, for that, what you can do is chmod, which will change the permissions. Don't worry if you are not aware of shell. We would learn them in the future and just change it to 600. Okay? Followed by your PM file location. It would modify the location, and then again, click on the up arrow and then enter the same command. Now, you will be successfully log, now you are successfully logged into the AWS instance. So, this is how you do it through the command line. Through the UI, I already showed you, just click on the connect button, click on the sorry, click on the instances, click on the connect button and you would be logged in. But if you want to do through the CLI, this is the process. Perfect. I hope now everybody is clear on I would again show you, if I click on LS, this is the file that we have created through the UI. That file will remain because the virtual machine is same. Now, let me do touch Abhishek2. Just to make sure that I'm able to create and I'm able to connect to the server through the CLI as well. So, if you see the file is created, and the file is created in the IP address. This is the, uh, IP address of your virtual machine. Uh, so your file is created in the AWS instance. So, with this, we learned how to connect to the virtual machine and how to create, uh, a file in the virtual machine just to ensure that the connection is established through the UI and the CLI. Perfect. So, using day four, day three and day five, what we have learned? We learned about the concept of virtual machine. We learned about how to connect to a virtual machine. How theoretically, we looked at the different options, right? We learned the concept of the API, how users can or how DevOps engineers can automate the process of creating the virtual machines using different script options, that is using the AWS CLI, or AWS CDK, CFT, Terraform, or the AWS API itself. So, these are the different options that are available. Now let's talk practically. Okay? Because we have lot, we talked a lot of theoretical stuff. Now, let's move to the practical things of it. So, firstly, let's start with the basic and the easiest one, that is the AWS CLI. Before I do that, I would show you how to delete an instance as well. Because I'm done with this, uh, specific instance. I can click here and I can say, uh, click on the actions. And uh, my bad. Okay. So, I have minimized the screen and now I, I'm slightly confused when I explain. So, what you do is you can go to the instance state and stop the instance first. Okay? You can also terminate the instance, but, uh, always the better practice is to stop the instance and then terminate the instance. Okay? So, once you terminate this instance, your instance will be deleted. If you don't want to use this instance one more time, you can simply shut down the instance, or you can also stop the instance, like, uh, when the stop is useful is let's say you're buying an instance from AWS. So, AWS does billing for you depending upon the time the server is in start state or in the active state. So, or in the running state. So, to avoid such problems, what you can do is when your work is completed, uh, or when you don't want to use this instance any longer, you can simply stop the instance or the terminate the instance completely. Perfect. Now, we are stopping and terminating the instance. While this goes on, what we'll do is we will look at each and every option to create, uh, the easy to instance practically. Okay? Or the automated way of things to improve the efficiency. The first option and the easiest option that is available today is AWS CLI. Okay? So, what is AWS CLI? Like I mentioned, AWS CLI is a command line interface. Using the AWS command line interface, what you can do is you can directly interact with your AWS API or using your uh or to your AWS account and create any resource on AWS. Okay? Today AWS provides you hundreds of services and all of these hundreds of services can be created using an automated way using AWS CLI. So, to achieve that, firstly you need to download the AWS CLI. What is AWS CLI? It's just a binary. Download AWS CLI. Okay? So, here is the here is the option, AWS command line interface, AWS CLI, or here you can also look at download, installing or updating the version of AWS CLI. Let me click on this option. And, uh, here, uh, I would, uh, go for an option called installation or download. Let me see if I find an option here. If you see here, here are different ways to install. If you are on Windows, you can click on this option. If you are on Mac OS, you can click on this button. And if you are on Linux, you can click on this button. Let's say you're on Windows. Simply click on this button. It would, uh, download a 64-bit MSI for you, and, uh, you can, uh, follow the steps like next, next, next, and it would install the package for you. After that, you can either add it to your path or you can use it from the location where you have installed. So, in my case, I'm on Mac, and I've already installed it. So, if I just come here and run AWS. So, how do you verify if your AWS is installed or not? Simply use the command called AWS space version. If you receive this, uh, sort of output, that means that your AWS CLI is installed. So, once your AWS CLI is installed, that itself will not do anything for you. Because you just installed an AWS CLI binary. But what is the actual thing? Your AWS CLI, this package that I have, this AWS binary that I have, okay, if I do which AWS, so this is just a binary, but this binary does not have my user information, or it does not have my account information. So, firstly, I have to authenticate with my AWS. So, for that, what you need to do is that go to your AWS console. You know, you have a user option here. Click on the drop-down. Once you come here, there is an option called security credentials. Click on the security credentials. Okay? Once you do that, scroll down, scroll down a bit. There is an option called access keys. Okay? Here, click on create access keys. Okay? Say I understand the risk. And then create access key. So, your access key is created, and this is the secret access key. So, this is access key and this is the secret for the access key. Now, do not share this information with anybody and once the video is completed, I would also delete, uh, the access key. I'm not even showing you the secret of the access key, but it is always safe to hide the access key as well as the secret for the access key. Okay? Now, once that is done, go back to your command line and use this command. AWS space configure. Okay? Now, it would ask you to enter the AWS access key ID. I would copy this from here. I would enter the access key ID. After that, it says AWS secret access key. Again, click on this button, show button. It will show you your secret access key. Enter that here. Finally, it will ask you the default region. You can keep it US East region one. Okay? Default output format, let it be JSON. That's it. Now you are authenticated with the AWS. So, now whatever command I enter here, will be reflected in the AWS. For example, now, uh, let me, uh, click on the services option here. Let me try to find the S3 buckets. Because S3 buckets are very lightweight. If you want to create AWS EC2 instance, it would require a couple of steps. So, I would show you with S3 bucket. So, let's say here there are three S3 buckets. You can see three S3 buckets, right? I want to get this information from the command line. What I can simply do? AWS S3 LS. See what will happen. Okay? Okay. So, just let me stop sharing because I want to enter the information for, for my, uh, access key ID. So, the previous access key ID I deleted. So, I have to re-enter the access key ID and the password. So, just let me stop sharing for a minute and I'll enter the credentials and then we can start sharing. I stopped sharing. I do AWS, I did AWS configure one more time. Then I went back to my AWS console to retrieve my, uh, secret key and the information.
[17:48]Okay? So, you have to go to the security credentials option. Perfect. Let me retrieve my uh access key here.
[18:03]Okay, I entered my access key. So, let me go back. Click on the copy. I copied the AWS secret access key. Now, I clicked on the enter. Default region JSON. Perfect. I think now I'm done with it, so let me start sharing here.
[18:44]Screen share started. Perfect. Now I just started the sharing back. AWS S3 LS. So, I want to get the same information that is available on the UI. If you see here, so these are the three S3 buckets, which my CLI is saying. Let me confirm if those buckets are correct. Okay? So, if I come back here, yeah, I have three S3 buckets, okay? That same information is retrieved from the AWS CLI. I can also create an S3 bucket by saying AWS S3 MB stands for make bucket. I'll say Abhishek 12345642. So, the S3 bucket name has to be unique, so that's why I'm, uh, okay. So, I have not provided enough arguments, but using the MB bucket, you can also create a bucket or you can do anything from the CLI. That was my main intention. Perfect. So, you understood how to deal things with AWS CLI. So, this was one way of automating. So, if you want the exact command for, uh, so what you can do is AWS CLI EC2 instance create. Okay? So, if you go to the AWS documentation, there is an option for each and every command that is here. So, using this command, you can create an AWS instance. Okay? So, the commands are directly available in the AWS documentation. So, if you just take this command, and, uh, if I provide this command here, but I have to provide the image information, I have to provide what is the type of instance that I want to use, what is my key value pair location, security groups and subnet ID. Okay? Once I provide all of this information and click on enter, my AWS EC2 instance will be created. But I don't want to take your time in providing all of these details. I think you will be able to, uh, read this documentation and, uh, create that stuff. It's not a big deal. So, I'm not going into the details of it. But using the S3 information, I showed you how to interact, right? All that so all the things that are important is how to create a, uh, security, uh, credentials, right? Once you create the security credentials, you have to authenticate. And once you are authenticated, then you can follow this reference documentation. The commands are pre-available, so you can just copy this commands for your automation. You can either put them in a shell script, Python script or anything that you want to do. Perfect. Or you can just, uh, store that in your GitHub repository and whenever you want to create an instance, you can simply use this command. You can clone it from your GitHub, uh, copy it and you can use this. So, this is one way of doing things, that is AWS CLI. So, till now, we looked how to do the things from the AWS UI. We also looked how to do the things from the AWS CLI. So, the next thing is how to do the things with AWS CloudFormation template. So, now what is CloudFormation template? So, if you remember our previous class, uh, don't worry, we are not going to the details of CloudFormation template because the CloudFormation template, Terraform, all of these things will fall into the infrastructure as code concept, which will be dealing in the future videos. But for now, CloudFormation templates are another way of talking with your AWS API, and, uh, so this is a GitHub repository. You can come here, called AWS Labs, this is the organization. There is a repository called CloudFormation template. And you have wide range of examples here. Click on AWS, then click on services. Let me go to the EC2 service and what I want to do is, I want to create an AWS EC2 instance. Okay? Go with this option. This is an example. And you have the entire script here. So, theoretically and practically, even I'm not going to remember all of this script. So, even I would refer for some examples, and I would use this script. Now, once you use this script, what you have to do is you can come here. So, this is my AWS screen. Click on CFT. So, this is the CloudFormation option. Go to the CloudFormation, and you know, you can create your own stacks using the template. So, click on the create stack option. Is the template ready? Use a sample template, or create template in designer. Okay? If you have a template already ready, uh, like, you know, in my case I have the template ready from the GitHub examples, or you can use a sample template here. Uh, in the sample you can select EC2. If you have EC2, you will get that sample. If you don't have, you can, uh, like I showed you, you can get that from a GitHub repository. The sample is ready. Perfect, the template is ready. You can upload either it from a S3 bucket or use, upload a template file. So, to upload a template file, you can copy this in your local and you can choose the file and click on the next button. So, that's how you create the AWS CloudFormation template. And using the CloudFormation template as well, you can create resources on your AWS. Now, don't worry, why I'm not explaining you the CloudFormation templates, why I'm not showing you how to create these things, because they fall into a different category, that is IAC, that is infrastructure as code, and we'll learn these things in the future videos. So, don't worry if you are not aware. For now, you understood how to create resources from the UI. You understood how to create resources from the CLI, that is more than enough, and CloudFormation template. You just got an idea of the things. Perfect. Now the next thing that we talked about is using the script automation, that is the AWS API itself. So, using the AWS API, you either have to write a shell script, or you can use, uh, your favorite programming language. Like, in my case, I want to automate the things using Python. So, like I mentioned you, Python has a support to a module that is called boto3. Okay? boto3 is a very well maintained Python module. So, they have a wonderful documentation as well. This is boto3.amazonaws.com. So, you have all the required documentation, how to install boto3. If you're new to Python as well, like, you know, they, uh, provide you the steps how to install this specific package and how to configure. Like, in our previous case, I showed you already. Once you do AWS configure, that is more than required. Because boto3 can pick the information from your AWS configure file. So, there is a configure file. And, uh, you know, once you run this command, boto3 can also pick the information from there. Once it is done, okay? We are not going into the details of boto3 and how we are going to write these scripts. But this is a very simple script. Like, you know, this script will create, or sorry, list running EC2 instances. And what is the thing that you have done as a developer, or as a DevOps engineer, you just write a Python file here. What you would say? Import boto3. And then these are the simple, uh, like, you know, steps that you would write in Python to list the EC2 instance. Let's say you don't know how to write this script. Okay? Don't worry, again, boto3 has a wonderful documentation, and using the documentation, you can, uh, easily learn how to write, uh, the boto3 commands. What is the request that you have to send? What is the response that you will get, and how to handle the response. These are the things. Okay? So, this is how you automate stuff on AWS, and the same thing will be applicable to the Microsoft Azure as well. So, what are the different things that we have learned? How to practically do it from the AWS UI, that is AWS console. Next thing that we have learned is to use AWS CLI. And for using the AWS CLI or for using the AWS boto3 module, the first thing that you have to do is you have to go to your account, and in the account, you have to click on the security credentials and you have to get access token. And then download the AWS CLI package, that is from the AWS documentation. And once you do that, we ran a command called AWS configure, right? Once you click on AWS, once you run the command called AWS configure, what will happen is it would ask you for the essential information, that is what is your access key ID, what is the secret for your access key ID. Once that information is done, you are good to go and you can play with the AWS through your CLI itself. So, that way, you can automate stuff around AWS. Okay. So, if you have any questions on today's video, you can put those questions in the comment section. Uh, as you know, I reply to each and every comment. And, uh, don't worry if you did not understand the concept of CloudFormation templates. There is a reason why I did not explain, because we are going to delete it with the IAC, that is Infrastructure as Code concept. Now, the assignment that I want to give here is to install the AWS CLI package by your own. And then create the security credentials and authenticate your AWS using your terminal, you can either use Putty, Mobile Xterm, or any other terminal that you want. And make a call with your AWS. You can either create S3 bucket, you can either list S3 bucket, create, list EC2 instances, whatever you want to do. Just go through the AWS documentation. Follow the commands. Like, uh, if you again want to look at the AWS documentation, so what you can simply come here, go to your favorite browser. Say, AWS CLI Doc. Excuse me, my bad. So, this is AWS CLI documentation. Here, you have example for everything. Okay? So, click on the command references. Let me just increase the font. And you can go with any command that you want. Okay? So, there are all the commands that are available. You can just go through. Let's say I want to go with S3. Click on the S3 option. And then with examples, they provide you everything. How to move a bucket, how to remove a bucket, how to copy objects into the bucket. Everything is available. And let's say today we learned about EC2, right? So, let me search for EC2. So, this is EC2. And I want to create an instance. So, search for create. Okay? Okay. Create instance export talk. Not not this one. You can search for run instance.
[28:42]Okay? So, run instances. And using this, you can, you know, basically provide all the required information here. You can just go through the documentation and you can create an instance. So, that is the task for today. Okay? Go through the AWS reference documentation because we cannot go through each and every topic here because we are not doing the AWS course. We are doing the complete DevOps course. So, what we'll do is we will only learn specific set of things. Like I mentioned, we will do the breadth of the knowledge. You have to do your homework. You have to, uh, do some assignments that I am giving to you so that you can get perfect on a specific topic. Now, don't worry, if you don't understand anything, put that in the comment section. Uh, and, uh, if many people are requesting for the same thing, I can extend one more class, and I can explain you how to, uh, do the things with the AWS CLI. But for today, I hope, uh, everything is clear, uh, with respect to the automation side of things. How to automate, uh, things, and how to, uh, create content on the AWS using the CLI, or using the CloudFormation templates, or using AWS boto3. So, there is a small request. Uh, don't forget to like this video and, uh, if you have a good or bad feedback, definitely mention that feedback in the comment section. I will definitely take your feedback positive. And after that, if you have any people that you know, they're planning to learn DevOps, or, you know, they have they are very passionate about learning DevOps. Do share these videos with them. Because, the main goal of doing the free DevOps course is to make an understand, uh, I mean, uh, make these videos reached to a larger audience, and maximum people are benefited from these videos. I hope you enjoyed the video for today. I'll see you in the next video. Take care. Thank you so much.



