EC2 is one of the most widely used services within AWS. As an Infrastructure as a Service (IaaS) product, it’s responsible for providing long-running compute as a service.
EC2 instances are grouped into families, which are designed for a specific broad type workload. The type determines a certain set of features, and size decide the level of workload they can cope with.
The current EC2 families are:
Instance Types include:
Instance sizes include Nano, Small, Medium, Large, X.Large, 2X.Large and Larger
Special Cases
Elastic Block Storage is a storage service that creates and manages volumes based on four underlying storage types. Volumes are persistent, can be attached and removed from EC2 instances, and are replicated within a single AZ.
To protect against AZ failure, EBS snapshots (to S3) can be used. Data is replicated across AZs in the region and (optionally) internationally.
EBS Snapshots are a point-in-time backup of an EBS volume stored in S3. The initial snapshot is a full copy of the volume. Future snapshots only store the data changed since the last snapshot.
Snapshots can be used to create new volumes and are a great way to move or copy instances between AZs. When creating a snapshot of the root/boot volume of an instance of busy volume, it’s recommended the instance is powered off, or disks are “flushed”
Snapshots can be copied between regions, shared and automated using Data Lifecycle Manager (DLM).
Security Groups are software firewalls that can be attached to network interface and (by association) products in AWS. Security groups each have inbound rules and outbound rules. A rule allows traffic to and from a source (IP, network, named AWS entity) and protocol. Security Group belongs to a VPC
Each Elastic Network Interface (ENI) can have upto 5 security groups.
Security group have a hidden implicit/default deny rule but cannot explicitly deny traffic.
They are stateful - meaning for any traffic allowed in/out, the return traffic is automatically allowed. Security groups can reference AWS resource, other security groups, and even themselves.
Instance metadata can be used to access information about an instance from the instance. It allows applications running within EC2 to have visibility into their environment. Instance metadata is data relating to the instance that can be accessed from within the instance itself using a utility capable of accessing HTTP and using the URL
http://169.254.169.254/latest/meta-data
Instance metadata is a way that scripts and application running on EC2 can get visibility of data they would normally need API calls for.
The metadata can provide the current external IPv4 address for the instance, which isn’t configured on the instance itself but provided by the internet gateway in the VPC. It provides the Availability Zone the instance was lanched in and the security group applied to the instance. IN the case of spot instances, it also provides the approximate time the instance will terminate.
Remember the IP address to access metadata: 169.254.169.254
AMIs (Amazon Machine Images) are used to build instance. They store snapshots of EBS volumes, permissions, and a block device mapping, which configures how the instance OS see the attached volumes. AMIs can be shared, free or paid and can be copied to other AWS regions.
Types of AMIs
Process of Creating AMI
Configure Instance - Source instance and attached EBS volumes are configured with any required software and configuration.
Create Image - Snapshots are created from volumes. AMI references snapshots, permission, and block device mapping.
Launch Instance - With approriate launch permissions, instances can be created from an AMI. EBS volumes are created using snapshots as the source, and an EC2 instance is created uinsg the block device mapping to reference its new volumes.
AMI’s can be used to build servers with complex configuration.
Downside of using AMI is you can’t do dynamic configuration
Bootstrapping is a process where instructions are executed on an instance during its launch process. Bootstraping is used to configure the instance, perform software installation, and add application configuraiton.
In EC2, user data can be used to run shell scripts or run cloud-init directives.
Bootstrap vs AMI: With AMI’s you can reduce time it takes to install and configure versus with bootstrap you can use shell commands to perform dynamic configuration.
EC2 instance roles are IAM roles that can be “assumed” by EC2 using an itermediary called an instance profile. An instance profile is either created automatically when using the console UI or manually when using the CLI. It’s a container for the role that is associated with an EC2 instance.
The instance profile allows application on the EC2 instance to access the credentials from the role using the instance metadata.
Volume encryption uses EC2 host hardware to encrypt data at rest and in transit between EBS and EC2 instances. Encryption generates a data encryption key (DEK) from a customer master key (CMK) in each region. A unique DEK encrypts each volume. Snapshots of that volume are encrypted with the same DEK, as are any volumes created from that snapshot.Encrypted DEKs stored with volume are decrypted by KMS using a CMK and given to the EC2 host.
Plaintext DEKs stored in EC2 memory and used to encrypt and decrypt data. The EC2 instance and OS see plaintext data as normal - no performance impact.
EBS encryption are configured at per volume basis but can also be specified on per-account basis.
If you need to manage the Keys and you need encryption on OS Level, EBS encryption won’t fullfill the need, you would need OS level encryption.
EBS-optimized mode, which was historically optional is now the default, adds optimizations and dedicated communcation paths for storage and traditional data networking. This allows consistent utilization of both - and is one required feature to support higher performance storage.
Restoring from EBS Snapshot - Not all data is copied immediately to the new volume. Data will be copied over time in the background. This preliminary action takes time and can cause a significant increase in the latency of I/O operations the first time each block is accessed which will temporarily adversely affect performance. Volume maximum performance is achieved after all blocks have been downloaded and written to the volume.
Traditionally, virtual networking meant a virtual host (EC2 host) arranging access for n virtual machines to access one physical network card - this multitasking is done in software and is typically slow.
Enhanced networking uses SR-IOV, which allows a single physical network card to appear as multiple physical devices. Each instance can be given one of these (fake) physical devices. This results in faster transfer rate, lower CPU usage, and lower consistent latency. EC2 delivers this via the Elastic Network Adapter (ENA) or Intel 82599 Virtual Function (VF) interface.
Use Cluster Placement Group for maximum performance
Use Partition Placement Group if you have large infrastructe platform and provides visibility on placement.
Use Spread Placement Group for maximum availability.
Default Billing Model of EC2 is per-second charge for compute instance.
Spot instance allow consumption of spare AWS capacity for a given instance type and size in a specific AZ. Instances are provided for as long as your bid price is above the spot price, and you ony ever pay the spot price. If your bid is exceeded, instances are terminated with a two-minute warning.
Spot fleets are a container for “capacity needs”. You can specify pools of instances of certain types/sizes aiming for a given “capacity”. A minimum percentage of on-demand can be set to ensure the fleet is always active.
Spot instances are perfect for non-critical workloads, burst workloads or consistent non-critical jobs that can tolerate interruptions without impacting functionality. Spot is not suitable for long-running workloads that require stability and cannot tolerate interruptions.
Spot instances are not suitable for long-running workoads that require stability and cannot tolerate interruptions.
Spot Pricing can save you more than 90% than on-demand application.
Reserved instance lock in a reduced rate for one or three years. Zonal reserved instance include a capacity reservation. Your commitment incurs costs even if instance aren’t launched. Reserved purchases are used for long-running, understood, and consistent workloads.
When to Use Reserved Purchases
When to Use Spot Instances / Fleets
When to Use On-Demand
EC2 dedicated hosts are a feature of EC2, giving you complete control over physical instance placement and dedicated hardware free from other customer interaction. Dedicated hosts are EC2 hosts for a given typ and size that can be dedicated to you. The number of instances that can run on the host is fixed - depending on the type and size. An on-demand or reserved fee is charged for the dedicated host - there are no charges for instance running on the host. Dedicated hosts are generally used when software is licensed per core/CPU and not compatibile with running within a shared cloud environment.
For dedicated host, you are paying for the hourly charge.