What is EC2 instance and Setup of EC2 instances.
Tags: aws, devops, ec2
Published: 2022-01-18 05:41:08

**<u>WHAT IS AN EC2 INSTANCE?</u>**

- Amazon EC2 stands for Amazon Elastic Compute Cloud.
- Cloud service providers like AWS, Azure and GCP etc. use hypervisors in their physical servers to virtualize it.
- EC2 instances are virtual machines (VMs) using those Hypervisors.
- EC2 provides scalable computing capacity in the AWS Cloud and eliminates your need to invest in hardware up front, so you can develop and deploy applications faster.
-EC2 helps to launch as many virtual servers as you need, configure security and networking, and manage storage.
- EC2 provides a wide range of instance types optimized to fit different use cases.
- Instances are virtual servers and have varying combinations of CPUs, memory storage and networking capacity.

##<u>FEATURES OF EC2 INSTANCE</u>##

• Virtual computing environments, known as instances AND Preconfigured templates for your instances, known as Amazon Machine Images Or AMIs.
• Various configurations of CPU, memory, storage, and networking capacity for your instances, known as instance types.
• Secure login information for your instances using key pairs (AWS stores the public key, and you store the private key in a secure place)
• Storage volumes for temporary data that's deleted when you stop, hibernate, or terminate your instance, known as instance store volumes.
• Persistent storage volumes for your data using Amazon Elastic Block Store (Amazon EBS), known as Amazon EBS volumes.
• Multiple physical locations for your resources, such as instances and Amazon EBS volumes, known as Regions and Availability Zones.
• A firewall that enables you to specify the protocols, ports, and source IP ranges that can reach your instances using security groups.
• Metadata, known as tags, that you can create and assign to your Amazon EC2 resources.

## <u>SETUP OF EC2 INSTANCE</u> ##

- Step 1: Sign-in to AWS account and open IAM console by using the following link: https://console.aws.amazon.com/iam/.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xi63nbb263hpim2lflzd.png)

- Step-2: In the navigation panel select EC2 service. On EC2 dashboard select instances from the left panel then click on launch instance. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59vf3ndyahs91eff0jl7.png)
-Step-3: Select an AMI from the list of various AMIs like( Amazon AMI, Linux AMI, Red hat AMI, Windows Server AMI etc.), let's select Amazon AMI.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3auyukk2rgmpyl3e7lp4.png) 
- Step-4: Select an Instance type from the list of instances, let's use "t2.micro" as it is eligible for free tier.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4k2nfkji7pj138lltmr5.png)
-Step-5: Configure instance details such as no. of instances you want to run or specify VPC network or Subnet. Here I've kept the specifications as default.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9ojqwzvaobglsdspd0r.png)
- Step-6: Add storage for your instance as per your requirement or you can select the default root volume.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2sa42n3vtzzo15j171dw.png)
-Step-7:  Add tags for your instance. A tag consists of a case-sensitive key-value pair. you could define a tag with key=Name and value = Webserver .A copy of a tag can be applied to volumes, instances or both.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahkou4j595zc37fnghfw.png)
-Step-8: Configure security groups. security group is a set of firewall rules that control the traffic for your instance. you can add rules to allow specific traffic to your instance. If you want to set up a web server and allow Internet traffic to reach your instance, add rules that allow unrestricted access to the HTTP and HTTPS ports. You can create a new security group or select from an existing one.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmhrubdhpbj4ge7p9qmu.png)
-Step-9: Review Instance Launch. 
You can Cancel Previous Launch, review your instance launch details, go back to edit changes for each section. Click Launch to assign a key pair to your instance and complete the launch process. Don't forget to download your key pair file.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnftgy6zv4yhzsrgea6l.png)
-Step-10: If your instance is successfully launched you can see Green check mark with instance state as "Running" and status as "2/2 checks passed" respectively.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uwh7vvfnanpf2z8yer4p.png)
- Step-11: You can connect your instance using public DNS of your instance via SSH client using command prompt or Xshell or using PUTTY/PUTTYGEN.
Here I've shown how to connect your instance using Xshell.
First Install XSHELL from this link: https://www.netsarang.com/en/free-for-home-school/
- paste your Public DNS in Xshell prompt and click accept. Then select Browse and select your private key pair file and open it. Your instance will now be connected via SSH.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5x4u03wocz58uqr55h02.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pb6hscws3p3yn4d5jk6j.png)

We can also perform the above steps for an windows server instance using RDP client.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/no3iy3dd2k8339rf0lky.png)
-After launching the instance select RDP client and download the RDP file. Then generate password and decrypt the password.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jhvf7feykm4ufrrqyh7r.png) 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xknntkv22whn4mdd7xuk.png)
-Now open the RDP file and login using the decrypted password. When you connect you will be redirected to the remote desktop server and you can can connect your instance remotely.

- Finally terminate the instance you have created otherwise you'll end up with bills from AWS.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmwywbx0n3ougu4ugkyk.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cz7x1b0fqcbebsubu5at.png)

__Thank you :)__