EC2 - Elastic Compute Cloud
Tags: beginners, aws, ec2, cloud
Published: 2022-04-03 11:18:38

{% embed https://youtu.be/8uP4fJ4uEwM %}
**Elastic Compute Cloud** is a web service by AWS which provides scalable computing capacity. Here Computing refers to processing power, memory, networking, storage, and other resources. It offers infrastructure as a service(IaaS).

Amazon EC2 eliminates your need to invest in hardware up front, so you can develop and deploy applications faster. It is highly scalable and pay-as-you-go model.  

## Benefits of EC2 - 


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

## Features of EC2 -

- Instances  - It is a virtual server for running applications on AWS infrastructure.

- AMI  - Amazon Machine Image is a template that provides information required to launch instances.

- Instance types  - Amazon EC2 provides a total of 8 instance types which are classified according to their use cases. Instance types comprise varying combinations of CPU, memory, storage and networking capacity to give the client a flexibility to choose the appropriate mix of resources for your applications.

- Secure Login  - It allow secure login for your instances using key-pairs.

- Regions and Availability Zones  - It is a physical location around the world where data centers are clustered. Each group of logical data centers are called Availability Zone. 

- VPCs(Virtual Private Clouds) -  It enables you to launch AWS resources into a virtual network that you've defined.


## Amazon Machine Image 
An Amazon Machine Image (AMI) is a template/prototype that contains a software configuration (for example, an operating system, server, and applications). From an AMI we can launch an instance, which is a copy of the AMI running as a virtual server in the cloud. 
It includes EBS, Launch permissions, a block device mapping that specifies the volumes to attach to the instance when it's launched.


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

In the below diagram, it shows how we can create and register an AMI which includes EBS snapshot or template that can be used to launch new instance or to create another copy of AMI within same region or different AWS region. If we want any changes then we can deregister AMI and then launch it again.

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

In simple words AMI is a base image(it can include different OS) using which we can launch instances.

## Creating an EC2 Instance - Hands on 

- Open the Amazon EC2 console at [click here](https://console.aws.amazon.com/ec2/)

- To launch an instance click on ec2
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py81obsrgyjhj9myj7fg.png)

- Click on instances to see the instances and their running status

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

- If there is no instance created you will see this 

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

- Click on new Launch instances and then it will show you all the AMIs that are available for different use cases.
We will select windows (Microsoft Windows Server 2019 Base - ami-0f9a92942448ac56f) to launch an instance of windows OS.


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

- On choosing the AMI, you will select the instance type according to your usage of CPU, RAM, Storage, bandwidth, if you are having free tier then only t2.micro is available.

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

- Then you will choose the number of instances to be created from the AMI which is the configure instance details, this is the part where you can choose if you want to create a VPC.
 

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

- Add Storage - Here you will decide the size and volume type according to your requirements.

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

- Add Tags - We can add tags for our convenience it will be easier to identify and manage our instances like name, department, etc.

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

- Configure Security group - Here we can decide how we want to access our instances, we can choose the protocol type(RDP,HTTP, HTTPS, SSH). RDP stands for Remote Desktop Protocol which will allow us to create remote desktop for windows. We can also decide who can access our instance. As you will see this warning 

> Warning
> Rules with source of 0.0.0.0/0 allow all IP addresses to access your instance. We recommend setting security group rules to allow access from known IP addresses only.


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

- Review and Launch will allow you to check your instance launch details. You can go back to edit changes for each section. Click Launch to assign a key pair to your instance and complete the launch process.


- On clicking launch, AWS asks for a key which you download and use to access via RDP download and keep the key safe as it only can be downloaded once. You can also select a previous key if you have a key generated already.


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


- As you can see your instance is in running state, Select the instance you want to connect and click on connect button

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

- Download the remote desktop file 

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

- Click on get password which you will need while login to the Remote desktop. Now upload the download .pem file or the key pair value that you have generated while launching the instance.

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

- After uploading click on decrypt password and copy the password so that you can use it to login the Remote Desktop Connection.

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

- Go to the downloaded remote desktop file and use the password to login.
Here you go with the remote desktop connection, create your application and it is totally independent from your personal computer having it's own property. 

Likewise you can create an instance for different AMIs.

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


- If you want to create a template of your instance then stop the instance from running and then you can create templates of launched instances. 


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

- Likewise, you can create an image of your instance to launch another instance using your saved image(my AMIs) instead of using AMI. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07nferqwunok07691pwl.png)


That's all for this blog. 
Next I will be creating a blog on Instances and their types.