Launch an EC2 instance with AMI in 1 minute (Step by Step guide) Updated 2022
Tags: aws, ec2, cloud, tutorial
Published: 2022-07-15 15:23:09

This article  will guide you to get started with AWS EC2, launch your first EC2 instance and Configure it.
After this step by step tutorial you will understand EC2 practically.

First of all, Go to AWS management console and login with root or IAM user. Then select **EC2** by searching it on global search box.
![1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdq3giczka2zuyj0kq8p.png)

### Launch Your Amazon EC2 Instance
- In the AWS Management Console on the **Services** menu, click **EC2**.
- Click `Launch instances` > **Launch instances**.
![2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ucsrzay7wdcx5e5p5gn.png)

### Step-1: Give name and tags
- First, give the name and tags to your instance. **Tags** enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or environment.
- Click Add Tag then configure:
   - Key: Name
   - Value: Web Server
     ![47](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82a5zzh3f00jrt5x687q.png)

### Step-2: Choose Application and OS Images [Amazon Machine Image(AMI)]
- Then choose instance type as 2nd step.
- An Amazon Machine Image (AMI) provides the information required to launch an instance, which is a virtual server in the cloud. AMI includes
  - A template for the root volume for the instance (for example, an operating system or an application server with applications)
  - Launch permissions that control which AWS accounts can use the AMI to launch instances
  - A block device mapping that specifies the volumes to attach to the instance when it is launched
- We can also create our own AMI but **Quick Start** list contains the most commonly-used AMIs.
- Click select next **Amazon Linux 2 AMI** (at the top of the list).
![4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3b7870h9ilc043by37a9.png)

### Step-3: Choose an Instance Type
- Amazon EC2 provides a wide selection of instance types optimized to fit different use cases. Instance types comprise varying combinations of CPU, memory, storage, and networking capacity and give you the flexibility to choose the appropriate mix of resources for your applications.
- Under Instance type, from the Instance type list, you can select the hardware configuration for your instance.
- A t2.micro instance has 1 vCPU and 1 GiB Memory.
![5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wdt04r3dn2re1sy44wpw.png)
- Choose the t2.micro instance type, which is selected by default. The t2.micro instance type is eligible for the free tier. In Regions where t2.micro is unavailable, you can use a t3.micro instance under the free tier.

### Step-4: Create Key pair (login)
We use key pair to securely connect to our instance.
![6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wysch13vhxqw3jbehi6y.png)
Create new key-pair if don't have any, then give it name and select RSA. Finally download the PEM or PPK file.  
🚨 ⚠️ **Warning**
Do not choose Proceed without a key pair (Not recommended). If you launch your instance without a key pair, then you can't connect to it.
 
### Step-5: Configure Network settings
![7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhc7sni0r6j411zbt3s8.png)
- Next to Network settings, choose `Edit`. For Security group name, you'll see that the wizard created and selected a security group for you.
- We can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:  
  - Configure Security Group:
     - Keep the default selection, and select Create a new security group.
     - Security group name: `Web Server security group`
     - Description: `Security group for my web server`
![8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjtqg1wisn8cet4cu3ay.png) 
- Add SSH(port-22) and HTTP(port-80) rules in `Inbound security groups rules` to access our instance from putty(ssh) and through web browser(internet) respectively.
- Keep the default selections for the other configuration settings for your instance.

### Step-6: Configure Storage
- Amazon EC2 stores data on a network-attached virtual disk called Elastic Block Store.
![9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p89erpns1ybnve99myz4.png)
- We will launch the Amazon EC2 instance using a default 8 GiB disk volume. This will be your root volume (also known as a 'boot' volume).

### Step-7: Advanced Details
- A field for **User data** will appear.
    - When you launch an instance, you can pass user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts.
    - Your instance is running Amazon Linux, so you will provide a shell script that will run when the instance starts.
- Copy the following commands and paste them into the User data field:
```
#!/bin/bash
yum -y install httpd
systemctl enable httpd
systemctl start httpd
echo '<html><h1>Hello From Your Web Server!</h1></html>' > /var/www/html/index.html
```
- Leave everything else as `default`.

## Review the **Summary** and Click **`Launch`**
![10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n86jqqfzblcwloo20adl.png)

## Connect to your Instance
There are multiple ways to connect to your instance.
  1. **Connect to EC2 instance using PuTTY**
  ![11](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nec1cfz7mei3nmvrinuq.png)
     - Open PuTTY
     - Provide the public IPv4 address( of your ec2 instance in the Host Name section.
     - On the left menu, expand SSH and click on Auth
     - Click on Browse and open the .ppk file
  ![12](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dxzzq6l1s7wwsr7lz3bz.png)
     - Now click open and `accept` if comes in prompt then login as `ec2-user.

     🚩🚩 **Important**
You can't connect to your instance unless you launched it with a key pair for which you have the .pem file and you launched it with a security group that allows SSH access from your computer. If you can't connect to your instance, see Troubleshoot connecting to your instance for assistance.

  2. **Connect using EC2 Instance Connect** 
    - Supported Linux distributions:
      - Amazon Linux 2 (any version)
      - Ubuntu 16.04 or later

   -  To connect to your instance using the browser-based client from the Amazon EC2 console
     - Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
     - In the navigation pane, choose Instances.
     - Select the instance and choose Connect.
     - Choose EC2 Instance Connect.
     - Verify the user name and choose Connect to open a terminal window.
      ![67](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjsx55qj8n9wkplmji19.png)
     - When you hit coonect it will open terminal in your browser lik this: 
       ![75](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xigbu2tbgla4bbcqawf.png)