Linn Linn Htun
Linn Linn Htun
AvatarLinn Linn Htun

EC2

August 2, 2023

EC2

Amazon EC2 (Elastic Compute Cloud) is the foundational compute service of AWS, providing resizable virtual servers in the cloud. This post covers EC2 instance types and families, pricing models (On-Demand, Reserved, Spot), security groups, key pairs, and how to launch and connect to EC2 instances.

EC2 ( Elastic Compute Cloud - Infrastructure as a Service)

Ec2 mainly consists of the capability of

  • Renting Virtual machines (EC2)
  • Storing data on a virtual drive(EBS)
  • Distributing load across machine (ELB)
  • Scaling the services using an autoscaling group (ASG)

EC2 uses to deploy our application. We can run different environments as we want such as Windows, Linux and macOS. EC2 performs bootstrapping.

EC2 Hands-on

Search EC2 Service > click instances > click lunch instances button > put Instance name > Choose operating system > choose instance type (up to you) > create key pair > click create > click create new key pair button > fill key pair name > choose RSA key pair type > choose key file format .pem > Network Settings > choose Allow Http traffic from internet > Click advance details dropdown > go user data textarea >

#!/bin/bash

# use this for your user data (script from top to bottom)

# install httpd (Linux 2 version)

yum update -y

yum install -y httpd

systemctl start httpd

systemctl enable httpd

echo "<h1>Hello world from $(hostname -f)</h1>"> /var/www/html/index.html

 

> click lunch instance button

 

* Note : Public IPV4 is always change after start and stop of instance. But private IPV4 never change.

 

 

 

EC2 Instance Type Overview

 

AWS has the following naming convention

eg. m5.2xlarge

m : instance class

5 : generation (AWS improves them overtime)

2xlarge: size within the instance class

 

EC2 Port to know

  • 22 = SSH (Secure Shell) - log into a Linux instance
  • 21 = FTP (File Transfer Protocol) - upload files into a file share
  • 22 = SFTP (Secure file transfer protocol) - upload file using SSH
  • 80 = HTTP - access unsecured websites
  • 443 = HTTPS - access secured websites
  • 3389 = RDP (Remote Desktop Protocol) - log into a windows instance

 

SSH login for Macbook

ssh -i filename.pem ec2-user@2.231.23.345

If you have any issues with SSH login pls use the below command :

chmod 0400 filename.pem

 

How to SSH login using Elastic IP

Firstly we have to create Elastic IP:

 Go Network & Security > Elastic IPS > click allocate elastic IP address > click Allocate button

After creating Elastic IP we can use it for any EC2 instance.

How to use it? 

click Elastic IPS tab > check Elastic IPs address as we want > choose instance in Resource type > choose instane that we want and choose private IP address

After Elastic IP attached to the EC2 instance, we can see Elastic IP under the instance. 

How to remove Elastic IP?

Choose Elastic IP that you want to remove > Action > issiassociate > action > click release 

Frequently Asked Questions

What is AWS EC2?

AWS EC2 (Elastic Compute Cloud) is a web service that provides resizable virtual compute capacity in the cloud, allowing you to launch and manage virtual servers (instances) with a wide variety of configurations for any workload.

What is the difference between On-Demand, Reserved, and Spot EC2 instances?

On-Demand instances charge by the hour with no commitment; Reserved Instances offer up to 72% savings in exchange for a 1 or 3-year commitment; Spot Instances use spare AWS capacity at up to 90% discount but can be interrupted with two minutes notice.