Amazon EC2 Basics
Tags: aws
Published: 2022-05-01 13:10:41

EC2= Elastic compute cloud (Infrastructure as a service)
It consists of :

- Renting virtual machines (EC2)

- Storing data on virtual drives (EBS)

- Distributing load across machines (ELB)

- Scaling the services using an auto-scaling group (ASG)


EC2 sizing & configuration options:

Operating system (OS): Windows, Mac, Linux
Compute power & cores (CPU)
Radnom-access memory (RAM)
Storage space: Network attached (EBS & EFS), hardware ( EC2 Instance store)
Network card: speed of card,  public IP Address
Firewall rules: security group
Bootstrap script( This means launching commands when a machine starts): EC2 user data

examples: t2.micro (Part of AWS free tier), t2.xlarge, c5d.4xlarge, etc.


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




**_EC2 Instance Types_**
Checkout this website for instance types: https://aws.amazon.com/ec2/instance-types/

For example, m5.2xlarge has:
m== instance class (General purpose)
5== generation
2xlarge== size within the instance class


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

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

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpardp420sb0amvyk7ar.png)
Check out instances: https://instances.vantage.sh/



**_Security Group_**


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

Classic Ports to know

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


**_EC2 Purchases_**

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

On demand

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

Reserved Instance

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

Spot Instance

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

dedicated host

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

dedicated instance

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

**_Shared Responsibility_**

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



**_EBS Storage Instance_**
1. EBS (Elastic Block Store):

- It is a network drive which can be attached to an instance. It can be detached from one EC2 instance and attach to another one quickly.

- It allows your instances to persist data even after termination.

- Bound to a specific availability zone

- In Free tier: 30 GB of free EBS storage of type General Purpose (SSD) 

- It is locked to an availability zone. For example, an EBS  volume in us-east-I a cannot be attached to us-east-Ib. To move a volume across, one needs to snapshot it.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8kz8akwp3odnvch615fh.png)
- You can control EBS behavior when an instance terminates. By default, the root EBS volume is deleted (attribute enabled) and other attached EBS volume is not deleted (attribute disabled)

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

Know more about EBS multi attachment: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes-multi.html


**_EBS Snapshots_**
You can back up your EBS Volume at any point in time by EBS Snapshot. You don't need to detach the volume to snapshot it. But it would be better if you do it. You can copy the snapshot in Availability zones.

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

**_AMI_**
Amazon Machine Image is basically a pre-package that runs behind the scene. We can create an AMI from the instance and copy it to create an instance later on.
Note: To create an instance , we need an AMI. Basically when we are beginner we use free AMI from market place but later we can create an instance and customize it and make it an AMI. After that we can create an instance using our customized AMI. There are lots of organizations who have there AMIs in marketplace so that we use them and they can earn money.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irdbo18ctm9gko4ai756.png)
After creating an instance, we need to make it an image and we are good to go. It is an AMI now. Go to AMIs and select it and choose launch instance from the image.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ni0t7loka72gehctttpe.png)
**_EC2 Image Builder_**
It is used to automate the creation of virtual machine and container images. (To automate the creation, maintain, validate and test EC2). It can be run on a schedule basis and it is a free service and you need to pay for the underlying resources only. 

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



**_EC2 Instance store_**

- 
It is a high-performance hardware disk. 

- 
Better I/O performance.

- 
EC2 Instance store lose their storage if they are stopped. Not good for long-term use.

- 
Good use case: Buffer/scratch/temporary content
For long term usage, EBS storage is a good one

- Risk of data loss if hardware fails

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

Local Ec2 instance storage has very high I/o rate

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6w4a0al4daduxz9q5nrn.png)
**_EFS== Elastic File System_**
Very costly but available in multiple region.

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


**_EFS vs EBS_**

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

**_EFS Infrequent Access( EFS-IA)_**

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


**_Shared Responsibility_**

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



**_Amazon FSx_**

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

**_Amazon FSx for Windows_**

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


**_Amazon FSx for Lustre_**

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



**_Summary_**

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