Amazon Elastic Compute Cloud (EC2) is the most popular computing service in AWS. It is very easy to use and lets you scale your cloud infrastructure on go.
Today I’m going to present the basic overview of that service.
So, let’s begin.
Basics
Amazon EC2 stands for Amazon Elastic Compute Cloud. It is a web service that provides resizable compute capacity in the cloud.
Features
- Termination protection is turned off by default
- On an EBS-backed instance, the default action for a root EBS volume is to be deleted when the instance is terminated. Additional volumes by default won’t be deleted.
- EBS root volumes of default AMI (Amazon Machine Image) won’t be deleted
- Additional volumes can be encrypted as well
Security groups
- All inbound traffic is blocked by default 🚫
- All outbound traffic is allowed by default ✅
- Changes to security groups take effect immediately
- You can have any number of instances within a security group
- Security groups are stateful
- If you create an inbound rule allowing traffic in, that rule allows traffic out automatically
- You can’t block a specific IP address using security groups. Use the Network Access Control List instead
- You can specify allow rules but not deny rules
Instance metadata
- Provided by AWS to get information about an instance (i.e. public or local IP)
Try it on your EC2 instance:
EC2 Placement Group
Placement groups are logical groupings or clusters of EC2 instances in the AWS region.
- Clustered Placement
- low latency
- high throughput
- a clustered group can’t span multiple AZ
- Spread Placement
- individual critical EC2 instances
- limit: max. 7 running instances
- a spread group can span multiple AZ
- Partitioned
- multiple EC2 instances (HGDS, HBase, Cassandra)
- a partitioned group can span multiple AZ
Please remember that only certain types of EC2 instances can be launched in a placement group:
- C – Compute Optimized
- G – Accelerated Computing (GPU)
- R – Memory Optimized
- I – Storage Optimized
AWS recommends launching instances in the homogenous groups (all instances should have the same type).
You can’t merge groups – they’re isolated. You can place existing instance into a placement group but you have to stop it first.
Pricing types
- On-demand
- Fixed-rate (by the hour)
- Reserved
- Capacity reservation (contract for 1 year or more)
- Spot
- Works like a stock market
- Relays on an Amazon supply-demand
- Allows you to bid the price
- If spot instance is terminated by Amazon you won’t be charged by Amazon (but you will be charged if you’ll do it yourself)
- Dedicated hosts
- Physical EC2 servers dedicated for your use
Block storage – EBS
Elastic Block Store is a block storage service dedicated for use with EC2 instances. You can think of it as a virtual disk in the cloud.
In simple words: this is the service responsible for provisioning storage for your EC2 instance. You’re configuring it during the Add Storage step in EC2 instance creator.
- Disk and EC2 machine are always in the same Availability Zone in EC2
- EBS volumes snapshots
- are stored in S3
- are incremental -> only changed blocks are moved to S3
- snapshots can be used to create AMIs
- you can change EBS volumes on-fly (which means changing sizes, storage types etc.)
- best practice: to create root device snapshot, you should stop the instance before
- Migration between availability zones:
- take a snapshot of EC2 volume
- create AMI
- use AMI to launch EC2 instance in the new availability zone