Beginners guide to AWS EC2
Tags: cloud, aws, beginners
Published: 2024-03-31 11:04:33

AWS EC2 stands for Elastic Compute Cloud. It is one of the most popular and widely used service offered by AWS. EC2 is a foundational pillar in the digital landscape of AWS ecosystem. It offers flexible and scalable infrastructure for businesses to thrive in the cloud. 

With EC2 users can provision virtual servers within minutes, choosing from diverse instance types tailored to specific workload requirements. Before EC2, managing computing resources posed challenges such as upfront investments in hardware and inefficient scaling. With EC2, businesses can provision servers on-demand, paying only for what they use, leading to increased agility, scalability, and innovation.

Following are different types of instance types EC2 provides:

- General purpose
- Compute optimized
- Memory optimized
- Storage optimized
- Accelerated computing

You can find more details about different instance types [here](https://aws.amazon.com/ec2/instance-types/).

## Launching a new instance

To launch a new EC2 instance, go to EC2 dashboard page.

- Click on “Launch instances” button.


![Launch Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smlc04481qshix3s7pp4.png)



- Give a name to the EC2 instance. Under “Application and OS images (AMI)” section. Select any available AMI. I have selected “Amazon Linux” as the AMI for this instance. An AMI, or Amazon Machine Image is a pre-configured template used to create virtual machines (instances) within EC2. It serves as a blueprint for launching EC2 instances, providing the necessary operating system, software packages, configurations, and even data stored on the instance’s root volume.


![AMI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rnt8tkw02kxnuou2yshd.png)



- Select an appropriate instance type as per your use case and workload. For the current instance  I am going with `t2.micro` type of instance. Create a new key pair login credentials. A key pair login is a security credentials that you can use to prove your identity when connecting to the EC2 instance.


![Instance Type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h51ht67a8qzw25i20kgz.png)



- Under the “Network settings”, you can configure a firewall and network settings for the EC2 instance. You can create a security group and specify inbound and outbound traffic rules to restrict access to the EC2 instance. We will discuss more about security groups in later sections.


![Network Settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya36crg78zscpwhju7zc.png)



- You can also configure storage for EC2 instance. AWS also offers EBS (Elastic Block Store), an easy-to-use, scalable block store service that you can use for EC2. For now, I am keeping the default configuration for storage.


![Storage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ja3gk69jt9dd5vuxbn4.png)



- Once you are done configuring the instance, click on “Launch instance” button to start the instance. After the instance is successfully launched. You can see its details in the “instances” section of EC2 dashboard.


![First Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ngt6aos46xgbkg2p4od.png)



## Instance Operations

You can stop, terminate, or reboot an EC2 instance from the dashboard by selecting the instance and clicking on “Instance state” option.


![Instance Operations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ngvvrmfzdqnepnqh44v9.png)



## Security Groups

A security group acts as a virtual firewall for EC2. Security groups are used to control the inbound and outbound traffic for an EC2 instance.

- **Inbound rules**: these rules define the incoming traffic allowed to reach the EC2 instances. You can configure inbound rules to permit specific IP addresses, ranges, or protocols (such as SSH for remote access or HTTP for web traffic)
- **Outbound rules**: these rules define the traffic allowed to leave the EC2 instances. These rules control the communication initiated by the instances.

A security group can be used with multiple EC2 instances and it can also reference another security group. Security groups are region/VPC specific which means that a security group created in `ap-south-1` cannot be used in `ap-northeast-3` region.

## Connecting to EC2 instance

Primarily there are two ways of connecting to an EC2 instance.

- **SSH**: You can connect to the instance using SSH. To connect using SSH you need to prove your identity using a key value pair that we created when launching the instance.
- **EC2 Instance Connect**: Using this way, you can connect to the instance using browser based SSH client.

To view more options on how to connect to the instance. Click on “Connect” button after selecting the instance from the dashboard page.