AWS EC2: Launching an Amazon EC2 instance
Tags: aws, cloud, devops, beginners
Published: 2020-12-29 18:56:01

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r4rqcrsp6gbt1lcikzmc.png)

In this post, We are going to create a **Linux virtual machine** hosted on the cloud (also known as Instance) using **Amazon EC2**. Amazon Elastic Compute Cloud (Amazon EC2) is an **IaaS (Infrastructure as a Service)** that provides secure, resizable compute capacity in the cloud.

---

###**To launch an EC2 Instance**
1. Sign in to the [Amazon Management Console](https://console.aws.amazon.com).


2. From the navigation bar, choose a suitable geographic region that meets your requirements.
*Tip: Choose a nearer geographic region from your location to get faster responses*


3. Choose **EC2** inside the **Compute** section of **All services**, It will redirects you to the **Amazon EC2 Console**


4. From the EC2 dashboard choose **Launch Instance**


5. **Choose an Amazon Machine Image (AMI)**
Select an appropriate Amazon Machine Image(AMI). An AMI is a template that contains the software configuration (operating system, application server, and applications) required to launch your instance
*Tip: Choose Ubuntu if you are not familiar with other machine images*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jo3i0ue4rzdsd4fme9ie.png)


6. **Choose an Instance Type**
Choose a suitable **Instance type** as per your needs. An Instance type describes the hardware specifications of the virtual machine (i.e. CPU, memory, storage, and networking capacity) and then click next.
*Tip: Choose t2.micro, Because it is the only instance type which is eligible for free tier*
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mv6j09gl3sjtzshk5eem.png)

7. **Configure Instance Details**
In this step, We can configure our instance i.e Network type, IP allocation, Monitoring, IAM role, etc. If you don't have any prior knowledge of cloud computing then I would recommend you to not change any setting and simply click next.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/zqwkp1oqpdr1udrfz9ao.png)

8. **Add Storage**
An **Amazon EBS Volume** is similar as physical hard drive. In order to store data, We need to attach EBS volume to an instance. You can attach any size of disk space as per your needs. Free tier eligible customers can get up to 30 GB of EBS. We are choosing  **25 GB** disk space with **General Purpose SSD (GP2)** instance type. 
Enable **"delete on termination"** checkbox. It will delete the disk space associated with the server, whenever the server will terminate.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hsw8lyfh6hb7ch1r518h.png)

9. **Add Tags**
A **tag** is a **key-value** pair that you assign to an instance to uniquely identify them from a group. It doesn't alter instance's functionality. Click on add tag button, Enter "Name" in key field and "myserver" in value field. then click next.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n6hom0l2deete36a0enk.png)

10. **Configure Security Group**
A **security group** controls inbound and outbound traffic from the server. There are set of protocol by which we can access the instance server i.e. HTTP, HTTPS, SSH. 
   * Click on Create a new security group in assign a security group section. 
   * Enter a security group name and description.
   * Now you need to define some protocol by which you are going to access the server. SSH protocol is added automatically, so you don't need to add it manually. Choose anywhere in source drop-down box of SSH protocol. This makes your server accessible from anywhere. Alternatively, You can bound the server with custom IP address as well. 
   * Now click review and launch.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4w9wfj0ybyi1nrp6nxlu.png)

11. **Review Instance Launch**
Review your instance launch details. You can go back to edit changes for each section. If all details are correct then you can click on launch.
  * It will ask you to **select an existing key pair or create new key pair**. A **key pair**, consisting of a private key and a public key which is used to access instance server securely. Creating a new security group for individual server is the best practice. 
  * Enter key pair name and click on Download Key Pair button, Once you are done downloading, Save this key in a secure folder and then click on Launch Instance button.
*Note:- If you lost your key pairs, then you will not able to download it again*.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/htcnumh6g3stp7w15ucc.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2ov80oqnhuxabz0v9h7o.png)


12. It takes 2–3 minutes to create an instance, Now click on the instance button in the left panel. It will redirect you to the page where you can see list of instances created by you.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9se4kvy4r87nokof8ef9.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hxmi05thaxxk4v7lnpck.png)
 
13. Wait until the instance state of "myserver" is changed from *pending* to *running*.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/c5au726sdw7sprgt63n1.png)


14. We have successfully created an instance server. Now, We need to access it using SSH. Click on instance go to details tab, there we can see Public IP, Just copy it.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/txj0xd5d2jrtmpzy16i3.png)


15. Open **Terminal** or **Command Prompt**, Go to the folder where you store the key pair file and type the command
`ssh -i key-pair.pem ubuntu@public_ip`
replace *"key-pair.pem"* with your key-pair file name and *public_ip* with your instance's public ip.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mubhp8qxii1kmnntytiw.png)


16. It will ask you to add server's fingerprint, then simply type *yes* and press enter 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lf3m6impj5nkjlsl70z6.png)


17. Type
``` 
sudo su -
sudo apt-get update
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/t3ci1w7fuqslc1dfmpv0.png)

So we have successfully created and accessed an instance server. With the help of ec2 instance we can build web server, database server, vpn server, game server, data analysis server, geolocation or map server and lot more.

We'll going to build or experiement all of this with our EC2 Server.

For more update, Follow me on [twitter](https://twitter.com/kalpitrathore) or [instagram](https://www.instagram.com/kalpit_rathore1/)