hello everyone my name is Abhishek and welcome back to my channel and welcome to one more episode of AWS Zero to Hero Series in this video we'll try to understand and deep dive into the concept of AWS ec2 let me tell you that ec2 is one of the most widely used and one of the most popular services that AWS provides so it is very important for you to understand both the theory and practical part of ec2 instances that's the reason why in today's video I'll not only teach you the theory part of ec2 but by the end of this video you will learn how to create an ec2 instance how to connect to that created ec2 instance and how to deploy an application onto the ec2 instance finally I'll also show you how to use this or access this application from outside world that means you have deployed this application inside the ec2 instance of your AWS platform but still you will be able to access this application from outside well that is from your laptop or any other place in the world so the Practical part is going to be interesting because this is your first application that you are deploying onto ec2 instance before that definitely you should understand the theory part as part of theory we will learn what is an ec2 instance why you need to use ec2 instance why is it very popular we'll try to see what are the different types of ec2 instances and finally understand the concept of regions and availability zones because we have so many things to learn let's quickly jump onto the video and understand what is an easy to instance first okay so the word or the term ec2 represents elastic Cloud compute right so what does it represent ec2 represents elastic Cloud compute some people might feel that you already know this but you know to keep everybody on the same page it is very important for us to start right from the basics and eventually as we go through the series we will definitely deep dive into some complicated topics and maybe you might not be knowing few things about ec2 so please be patient with us and you know watch the video till the end so elastic Cloud computer now there are three words in this right first one is elastic cloud and compute the word compute means that you are requesting AWS to provide you a compute instance which is a combination of CPU RAM and disk so technically you are asking AWS to provide a virtual server right so when you request AWS to give you an ec2 instance what exactly are you requesting you are requesting AWS to provide you a virtual server now what is a virtual server I explained multiple times previously but just to give you a very simple overview virtual server let's take a physical server personally let's take your laptop and your laptop is something it's a physical server and you are the only one who is using it right let's say you want to use this laptop it it has to be divided by two to three people so what you can do is you have to install a hypervisor on top of your laptop and you can create some logical isolated virtual machines so that not just you but multiple people can use your laptop so your laptop is a very small thing whereas if you talk about a server server comes up with a huge resources so if you use this concept of hypervisor and virtual machines you can take one physical server and share it amongst multiple people and the same thing AWS does so when you request AWS for an ec2 instance AWS has multiple physical servers across the world so it has physical servers data centers in your as in Europe in India and multiple places when you ask AWS to give me an ec2 instance in this specific region of the world what it will do is it will take this request to the hypervisor that AWS has or the virtualization platform that AWS has and it will give you a virtual machine so that is AWS that is elastic Cloud compute so you understood what is compute now what does cloud represent here of course AWS is a public Cloud platform uh that's fine uh it means a cloud compute a cloud compute instance or a cloud virtual machine instance that you are getting now what does elastic represent here so the word elastic whenever you use AWS you will notice that there are multiple resources or multiple services that AWS provides and it has a prefix term called elastic now why there is prefix to some of the services in AWS with elastic and why some of the services does not have this prefix so the answer is very simple whenever AWS provides you a service that can be scaled up or scaled down that means this service is elastic in nature where you can increase the resources decrease the resources or use this resource in any way in that sense AWS calls these Services as elastic services for example you have elastic Cloud compute you have elastic kubernetes service elastic bean stack elastic load balancer so you have lot of services on AWS with prefix with this term called elastic so finally you might have understood what does this mean now elastic Cloud compute that means you are asking AWS to give me a virtual machine on your Cloud platform which is elastic in nature that's why it is called as e c c there are two C's here in shortcut we call it as ec2 2cs represents C2 now I hope you understood the concept of what ec2 instance is so to just summarize and explain you in one line ec2 means elastic Cloud compute where you are requesting AWS the public cloud provider to give you an virtual machine or to give you a virtual server which is elastic in nature and this term in general is called as a compute that's why we call it elastic Cloud computer now let's try to understand the Y aspect okay now Abhishek you told me what is an ec2 instance but why should I use an ec2 instance right so what is the advantage if I use an ec2 instance of course uh you have advantage that is instead of creating uh these ec2 instances let's say as a devops engineer you start creating instances you start uh installing your own hypervisor you can tell me that okay Abhishek I'll go to IBM or HP and buy a physical server and on top of it I'll install my own hypervisor and I'll start creating this virtual machines and I'll start giving it to devops Engineers uh sorry developers or queue Engineers let's say there are thousand requests okay so what you will do is using the virtualization platform probably you will write some shell scripts or you will do something and you will create this thousand virtual machines but now let us see as a devops engineer what are your activities after you create okay creating is easy probably will write a simple shell script and you will create ec2 instances thousand ten thousand I mean virtual machines how many ever you want but after creating you have to timely that means every now and then you have to upgrade these virtual machines right you have to verify the versions every now and then you have to upgrade these versions verify that they don't have any security issues right and verify if there is any issue like you know for some reason uh the server has gone down and the developers or the queue people will say that hey uh something is not working the server has gone down now to manage thousand resources like this it will be a huge headache if you are a one single devops engineer then managing thousand servers always checking the upgrades security issues and if the server is up or not probably you will end up wasting your whole day just doing this activity as a devops engineer or system administrator so one of the major advantage to moving towards the public Cloud platform is to get rid of this maintenance right so instead of dedicated people managing or looking into the issues upgrades and security of the virtual machines AWS will take care of this entire thing for you so what has gone down the management effort and again the another Advantage is that the cost as well so if you are doing this thing at your end because you will do it at a very small scale whereas AWS is doing this at a very huge scale so AWS technically is used today by a lot of organizations and AWS has a lot of servers they have already purchased these things and they do it if they do a lot of effective virtualization so for that reason AWS gets these things for very less cost and you will buy these things from AWS in a concept of pay as you go so let's say you don't want these servers to be up during the night you don't want the servers to be up during Christmas you don't want the servers to be up during Diwali because nobody is using it so in such cases what you can simply do is you can shut down these servers and AWS will not ask you for money for the time period where you have shut down these servers whereas if it were your own servers you are creating on your physical machines you have to anyways pay for it you have already paid for it because you have already purchased it so two reasons one is the maintenance and one is the cost that's one of the main reasons why people are moving towards ec2 instances and why people are moving towards the ec2 public Cloud compute instances I hope you understood this one and the other aspect the elastic thing you can also do it physically like you can add additional volumes you can decrease the volumes you can increase or decrease the RAM size and all similarly on AWS platform also you can do it now once we understood what and why an ec2 instance let's try to see what are the different types of ec2 instances so multiple types of ec2 instances and at this point of time just try to understand just try to sink in these things you don't have to worry oh there are so many types of ec2 instances how will I understand this eventually throughout the course whenever I am using the AWS UI I'll keep explaining you these things and you will get very familiarized with this but to explain now there are five different types uh which are very uh commonly used there are uh you know previous generation ec2 instance types as well but let's only learn about the current generation ec2 instance types so you have general purpose ec2 instances you have compute optimized ec2 instances then you have memory optimized storage optimized so you have memory optimized you have a storage optimized and you have accelerated compute so this thing keeps changing so you know uh probably two years down the line AWS might add two more different types of AWS ec2 instances you don't have to worry about it uh these things can be easily learned by using the AWS documentation I'll also uh point you out to that documentation when we do the practicals now what I want to tell you here is what are these different types now you told me that Abhishek ec2 is a very easy concept you are just creating easy to instance on AWS now why you have so many things so don't get confused you have these things even when you are doing at your organization as well for example you have a physical server let's take example that you purchased two machines from IBM okay so let's forget Cloud for a while and let's say that you are the system administrator who is taking care of all of these things let's say you have two instances that you have purchased two physical servers and IBM says that hey which type of server you want do you want memory optimized or do you want compute optimized or do you want storage optimized now what does that mean like you know this server that you have purchased is very rich in terms of memory that means the memory operations are performed very quick whereas you have another thing where which is compute optimized what does compute optimize means that means you know this instance provides higher ratio of compute power when compared to memory whereas memory optimized it provides High memory in terms of like you know in terms of power so this specific server that you have purchased are designed to handle more memory intensive workloads uh for example let me give you a basic example that you have some big data analytics applications or you have some high performance Computing applications uh these days people are using this Bitcoins and all of these things which are which requires heavy compute thing right so for all of these things like you know there is a difference whether you want to go with compute optimized or whether you want to use memory optimized so when you will go for memory optimized when you want to use some uh real-time big big data analytics or high performance Computing when you will use compute instance when you want to use some uh you know machine learning models or gaming servers in such cases you will buy a compute oriented one from IBM similarly what AWS tells you is okay you have requested an ec2 instance from me now which type of ec2 instance do you want do you want an ec2 instance that is compute optimized or do you want an ec2 instance that is memory optimized do you want an ec2 instance that is storage optimized or AWS will say hey don't worry about it do you want me to just give a general ec2 instance right so there is another term called general purpose where you know for example throughout all of these series that we are doing we will just use a general purpose ec2 instance because we don't want any memory optimized or compute optimized I am not writing any gaming application and deploying it there or I am not writing any machine learning application we are not doing any data analytics so technically throughout this demo or throughout this entire series will not be using uh these uh memory I mean all of these instance types will be only using general purpose instance types but it is very important for you to understand in future when you join a company or in your current organization if you want to implement AWS during your interviews also people will ask you what are the different types of ec2 instance so you need to tell them that depending upon the application if it is machine learning application if it is data analytics application or this application requires huge storage depending upon that I will choose what type of ec2 instance is required now don't worry the steps to create the ec2 instances are exactly same the only difference is when you do it through the UI or when you do it through the CLI you need to just select this instance type and AWS will give you this instance type and AWS will also charge you accordingly okay so AWS will not give you a memory optimized insta stands at the same price as a general purpose instance because AWS might have also purchased these servers at higher higher price right so this is this is something like the different types of ec2 instances so you need to remember this uh I will tell you that whenever someone asks you in the interviews you need to have this back of your mind that there is not only general purpose ec2 instance but there is general purpose compute optimized memory optimized storage optimized as well as accelerated Computing ec2 instances so like I told you don't worry much at this point of time when we move to the next videos when we do the practicals we keep seeing these ec2 instances every day so as part of this like every day whenever I go to the UI I'll show you like okay uh you know when you select this specific thing this is memory optimized this is come to compute optimized or this is general purpose now the next thing that we want to learn is what is the concept of regions and availability zones I can explain you very quickly but I want to show it practical so region in AWS is nothing but like I told you AWS have their data centers across the world right so AWS has the data center in India AWS has the data center in U. S Europe and multiple other places so this thing in AWS is called as regions so AWS allows you you can request AWS like give me ec2 instance in Europe in Europe you can also tell AWS to give me in this specific region like what are the regions AWS supports I'll show you don't worry but for now just understand that AWS has multiple regions so why you need ec2 instance created in a specific region there are multiple multiple reasons like for example you are working for a European client and they want the data to be very sensitive and they want to keep their data as close as possible to them so what you will do is as a devops engineer you will create ec2 instance that is very close to your client location in the Europe similarly you can create this ec2 instance in other regions like India if you are in India and you want very less latency latency is nothing but the request will take a lot of time to move from one place to another place if your servers are far away so this is the concept of regions and inside each region you have multiple availability zones as well so in India AWS does not have one single zone or one single data center it has data centers in multiple places this is called as availability zones now I'll show you these things on the AWS UI so that you will understand this in a much better way so let's quickly move on to the practicals we'll learn these things and we'll also do the practicals of deploying the application okay okay now I've logged into the AWS console uh using my user details and this is the thing that I'm talking about if you click on this button here you will see lot of regions right what are these regions basically these are the regions where AWS have their data centers across the world for example AWS says that they have data centers in North Virginia Ohio California Oregon Mumbai Singapore Sydney and apart from this you will see some 10 new regions which are not enabled by default because they are the new regions which are created after 2019 by AWS and they need to be enabled they are not enabled by default we'll talk about these things in future classes right now understand that these are the reasons that AWS provides you out of the box right it's up to you to decide in which region you want to create ec2 instance now why is this important as I told you let's say you have a European Bank as your customer today you are working for a European Bank in your organization there is a restriction with the European banks that they don't want to put their data outside their country or outside Europe okay so for that reason what they'll say is whenever you create an ec2 instance for me create that ec2 instance within the Europe zone or let's say your customer is in Germany so they'll ask you to create within the Germany there is a region called Frankfurt right Frankfurt is in Germany so you will create your ec2 instance in Germany so that your customer feels safe similarly let's say your customer or your end customers or your client is in the US and if you create an instance in Mumbai what happens is whenever they try to request or get some information from the application from the US they have to make request to one of the servers in Mumbai there will be latency what is latency latency is nothing but the time that is taken for the request to reach the application and for the application and the server to send the response back to you so this entire process if there is a delay that means there is high latency if there is no delay that means there is low latency right so everyone in this fast pace World expects your application to have low latency expects your server to send the response as quick as possible that's why as a devops engineer you will take care of these two things security latency and you will create instance in the appropriate region whenever you are dealing with the free instance you don't have to bother about it because you know you are doing a proof of concept you are trying to learn AWS then that's okay you can create all your instances in one region but when you work for an organization this is important and once we understand the concept of region there is another thing called availability Zone like I told you now what happens with availability Zone you might ask me like Abhishek they already have regions in multiple places across the world now why they want availability zones question is answer is very simple here let's say there is a customer who has created an instance in North Virginia and you have created that application for them deployed that application in that region everything is going well customer is accessing the application but one fine day what happened is that there was a short circuit or for some reason the region went down uh there was some reliability issues with that uh site or North Virginia then what will happen is that your customer will face downtime and your application stops working to avoid this problem what AWS said is even within a region we will have multiple availability zones for example if you have selected a region called Mumbai then AWS says that we have availabilities on in south of Mumbai in north of Mumbai I'm just giving you an example okay so similarly what AWS says in North Virginia we have two availability zones called us East one a U. S east 1B so instead of AWS revealing the server and data center location what they will say is they will use some alphabets to I to denote that okay you have two availability zones within a region called U.
S east 1A and U. S east 1B so wherever you want you can create the instance if you want High availability if you want that you don't want to run into issues like application not available keep your data in a highly available mode then you can even put your application into availability zones even if one goes down still customer can access your application so we will be doing High availability data replication all of these Concepts in future classes for Now understand the concept of regions and availability zones I hope it is clear now let's go on to the creation of ec2 instance so we discussed a lot about ec2 instance we understood regions what why everything about ec2 instance let's practically create one so go to your AWS this console and click on easy to in the last class we did the same thing for IM and we found a service called IM and we started creating users and groups right similarly now as I enter ec2 you will find this service called ec2 which says virtual servers in the cloud exactly what we discussed 15-20 minutes ago click on this ec2 button click on the instances here this is an ec2 dashboard where AWS tells you everything like you know these are the availability zones that are available where you can create you can enable additional availability zones what are the instances that you have currently created and some of these terms you might not be aware at this point of time security groups snapshots elastic IPS we will cover these things as part of future classes don't worry about it it's too quick to learn about these things at this point of time click on the instances button and click on launch instance now when you click on launch instance you have multiple options here and you have to fill lot of details I'll explain you each and every detail here try to understand it very clearly first provide the name of the instance let me call it as my first instance after this you can choose the operating system okay so what does operating system mean here if you understand the concept of Linux whenever you create a ec2 instance whether it's a virtual server or a physical server you need to have an operating system operating system is the technically heart of your virtual machine so we discussed in detail about operating operating systems virtual machines kernels in the free devops course devops Zero to Hero course I'll put the link below so that you can watch that video and understand the concept of virtual machines Linux kernel and everything in detail so AWS by default has all of these uh operating systems which are basically distributions right Linux and windows is an operating system on top of it you have different distributors like you can either pick Ubuntu Amazon Linux Red Hat Solaris you can pick anything here Debian so let's say I want to choose Ubuntu you can choose anything of your choice and once you choose Ubuntu again AWS says which version of Ubuntu do you want right so make sure you always pick the free tire eligible things only the reason is that if you pick anything else then AWS will charge you for that okay so pick free tire eligible resources and make sure that you understand the concept of free tire like AWS will not give you everything for free there is a restriction for everything for example if you want to use ec2 instances you can only use free tire ac2 instance for 750 hours only that means even if you are using free tire resources there is a time limit the retails are very clearly mentioned here whenever you use free tire understand that AWS provides you only 750 hours of T2 micro which is Fritter available eligible instance if you are using anything other than T2 micro you will be anywhere starts but if you are using T2 micro which is one CPU and 1 GB Ram only then you get 750rs free for one month it's not for the year but it's one month if you try to understand what is 750 Hertz it's basically 24x7 and every day in a week that means every day in a week throughout month if you have your instance running then there is no problem but only one instance let's say I create an instance today and throughout the year even if I keep that instance running AWS will not charge me but if you create one more instance then AWS will charge you for that instance so what people do is let's say they want to use two to three instance then they manage that time accordingly so you can manage one instance for 200 of ours sorry 200 hours another instance for 200 of 200 hours and rest instances for that specific time that is available in that way you can manage but you cannot exceed this specific time limit so always make sure it's a good habit whenever you are done with your proof of Concepts today you are learning something once you are done with it just try to turn off that instance or shut down that instance cool you understood what this is about now there is another thing here which I am just talking about that the instance type see here that free tire is only eligible for T2 micro which belongs to family T2 one CPU 1GB memory that's it like your laptop currently that you are using probably might be at least 4 GB 6 GB 8GB there are 32GB laptops as well what AWS providing Us for free is a very small thing right but that is a free tire instance and we will try to learn mostly with that free tire instance only and let's say you have some AWS credits or your organization provides you AWS credits for learning then you can go and try to explore other instances as well for example T2 x large which is 4 CPU and 16 GB Ram like you can run very good applications on this even the memory intensive applications or you know applications that consume require a lot of CPU and memory can run on this instance but on the t2 micro that we are creating we cannot run a lot of instances applications then you have key value pair or key pair which is the most important thing and this key pair is actually the one that helps us log into the instance what does that mean now you created one instance let's say in North Virginia how do you connect to that instance by default when you create an instance AWS does not provide your password the password authentication to the instance is disabled by default the only way you can log into the instance is using key value pair what is key value pair key value pair is nothing but a combination of public private key which you used to log into that specific instance so the instance has public key you will have the private key using the private key you will log into that instance and do not share this public private keys with anyone like even if you share public key that's okay but private key should not be shared with anyone so keep this key pair with you and not to be shared with anyone so I have a lot of key pairs here but for the purpose of video I'll create a new keypad just click on this button create new key pair use the default method RSA token and enter if you enter enter something that you will remember for example AWS login do not change any format and just click on the button create key pair so you can see here the key value pair is downloaded I have something called AWS login dot pem I'll use that AWS login. pam or any of my previous credentials to log into this but for the purpose of video I'll show this with AWS login itself like I can use any previous key value pair I can select anyone here if I select Abhishek underscore devops then I can log in with that key value pair but let's use the same thing that we have just created AWS underscore login and here you have bunch of network settings which will not touch today in today's video we will just keep these things as is in future video when we learn about networking when we learn about lot of Concepts like security groups inbound outbound traffic rules route tables then we will get to all of these things but for now do not change anything Additionally you can increase the storage by default the instance that AWS gives you has only 8 GB Ram 8GB is very less like for example your laptops has uh 501 DB 2tb but AWS gives you very less and for applications I think that's very good enough so we have 8GB Ram here now just come here and click on the launch instance and as you do it your instance will be launched within minutes so once the instance is launched what will you do is just use the key value pair and log into the instance if you are on Windows then you need to install something like putty or you need to install mobile extern or any other softwares but if you are on Mac then you can use the default terminal right so for the people who are new and who don't know about these softwares just go to internet search for putty or search like just say put a download you'll get this software called Puti you can use this or just click on the download button or you have something called mobile extern which is slightly more advanced and you have you can keep sessions for 10 instances you can store the passwords and all so mobile exterm is another good option uh just go with the free version do not go with the professional Edition download it and you can start using there is nothing that you have to do just download this instance and from there I'll show you how to do it perfect now let's see if the instance is launched or not go back and you will see that the instance is in running State you have to wait for the instance to be in running state now click on the instance ID and you will get the complete details of the instance so this is the public IP address using this public IP address you can access the instance from outside world this is private IP address that is very specific to the AWS Network so when we learn about the subnets and uh you know internal uh AWS networking you will understand what is this private IP address and how can you use it but for logging into the instance and learning AWS what we will do is we will use this public IP to log into the instance and create the application right next we will do is we will create an application and we will access the application from outside so just copy it and what you will do is take a terminal like I have a terminal by default so I'll just bring up the terminal so this is the terminal that I have again you might depending upon your laptop you have different types of terminals I'm not going into the details of that because that's a different discussion but the popular ones are putty mobile extern or if you're on Mac you can directly use the terminal like I am using so now if I do LS hyphen LTR I'll get the latest uh one okay let me do this instead of this I know the location of my pen file I have downloaded it so it will be in the downloads folder I'm already in the downloads folder what I'll do is SSH you see the command you have to use the same one SSH minus I go to the location of your mem file which is mostly in the downloads folder and what you will do is search for that mem file AWS login.
pam after that because we have created an Ubuntu instance the user ID by default available on that instance is Ubuntu so I'll say Ubuntu at the rate the public IP address so this is the public IP address right now as soon as I do it I log I land into an error so what is this error you have additional permissions for example if I just say yes you will notice that there is an error called the permissions for AWS login.