Amazon EC2 Cheat Sheet
- A Linux-based/Windows-based/Mac-based virtual server that you can provision.
- You are limited to running On-Demand Instances per your vCPU-based On-Demand Instance limit, purchasing 20 Reserved Instances, and requesting Spot Instances per your dynamic Spot limit per region.
Amazon EC2 Features
- The AWS Nitro System is the underlying platform of the next generation of EC2 instances. Traditionally, hypervisors protect the physical hardware and bios, virtualize the CPU, storage, and networking, and provide a rich set of management capabilities. With the Nitro System, these functions are offloaded to dedicated hardware and software, thereby reducing the costs of your instances in the process. Hence, the Nitro Hypervisor delivers performance that is indistinguishable from bare metal and performs better than its predecessor, the Xen Hypervisor.
- Server environments are called instances.
- Package OS and additional installations in a reusable template called Amazon Machine Images.
- Various configurations of CPU, memory, storage, and networking capacity for your instances, known as instance types
- t-type and m-type for general purpose
- c-type for compute-optimized
- r-type, x-type, and z-type for memory-optimized
- d-type, h-type, and i-type for storage optimized
- f-type, g-type, and p-type for accelerated computing
- Secure login information for your instances using key pairs
- Storage volumes for temporary data deleted when you STOP or TERMINATE your instance, known as instance store volumes. Note that you can stop an EBS-backed instance but not an Instance Store-backed one. You can only either start or terminate an Instance Store-backed instance.
- Persistent storage volumes for your data using Elastic Block Store volumes (see AWS storage services).
- Multiple physical locations for deploying your resources, such as instances and EBS volumes, are known as regions and Availability Zones (see AWS overview).
- A firewall that enables you to specify the protocols, ports, and source IP ranges that can reach your instances using security groups (see AWS networking and content delivery).
- Static IPv4 addresses for dynamic cloud computing, known as Elastic IP addresses (see AWS networking and content delivery).
- Metadata, known as tags that you can create and assign to your EC2 resources
- Virtual networks you can create that are logically isolated from the rest of the AWS cloud and that you can optionally connect to your network, known as virtual private clouds or VPCs (see AWS networking and content delivery).
- Add a script that will be run on instance boot called user-data.
- Host Recovery for Amazon EC2 automatically restarts your instances on a new host in the event of an unexpected hardware failure on a Dedicated Host.
- EC2 Hibernation is available for On-Demand and Reserved Instances running on freshly launched M3, M4, M5, C3, C4, C5, R3, R4, and R5 instances running Amazon Linux and Ubuntu 18.04 LTS. You can enable hibernation for your EBS-backed instances at launch. You can then hibernate and resume your instances through the AWS Management Console or the AWS SDK and CLI using the existing stop-instances and start-instances commands. Hibernation requires an EC2 instance to be an encrypted EBS-backed instance.
- You can allow the automatic connection of one or more EC2 instances to an RDS database.
Instance states
- Start – run your instance normally. You are continuously billed while your instance is running.
- Stop – is just a normal instance shut down. You may restart it again anytime. All EBS volumes remain attached, but data in the instance store volumes are deleted. You won’t be charged for usage while the instance is stopped. You can attach or detach EBS volumes. You can also create an AMI from the instance, and change the kernel, RAM disk, and instance type while in this state.
- Hibernate – When an instance is hibernated, it writes the in-memory state to a file in the root EBS volume and then shuts itself down. The AMI used to launch the instance must be encrypted, and the root EBS volume of the instance. The encryption ensures proper protection for sensitive data when it is copied from memory to the EBS volume. While the instance is in hibernation, you pay only for the EBS volumes and Elastic IP Addresses attached to it; there are no hourly charges.
- Terminate – instance performs a normal shutdown and gets deleted. You won’t be able to restart an instance once you terminate it. The root device volume is deleted by default, but any attached EBS volumes are preserved by default. Data in the instance store volumes are deleted.
- To prevent accidental termination, enable termination protection.
- By enabling instance stop protection, you can prevent an instance from being accidentally stopped.
Root Device Volumes
- The root device volume contains the image used to boot the instance.
- You can replace the root volume of a running EC2 instance using the following:
- Initial launch state
- Snapshot
- AMI
- Instance Store-backed Instances
- Any data on the instance store volumes are deleted when the instance is terminated (instance store-backed instances do not support the Stop action) or if it fails (such as if an underlying drive has issues).
- You should also back up critical data from your instance store volumes to persistent storage on a regular basis.
- Amazon EBS-backed Instances
- An Amazon EBS-backed instance can be stopped and restarted without affecting data stored in the attached volumes.
- When in a stopped state, you can modify the instance’s properties, change its size, or update the kernel it is using, or you can attach your root volume to a different running instance for debugging or any other purpose.
- By default, the root device volume for an AMI backed by Amazon EBS is deleted when the instance terminates.
- Previously, to launch an encrypted EBS-backed EC2 instance from an unencrypted AMI, you would first need to create an encrypted copy of the AMI and use that to launch the EC2 instance. Now, you can launch encrypted EBS-backed EC2 instances from unencrypted AMIs directly.
Amazon EC2 – AMI
- Includes the following:
- A template for the root volume for the instance (OS, application server, and applications)
- Launch permissions that control which AWS accounts can use the AMI to launch instances
- A block device mapping that specifies the volumes to attach to the instance when it’s launched
- Backed by Amazon EBS – root device for an instance launched from the AMI is an Amazon EBS volume. AMIs backed by Amazon EBS snapshots can use EBS encryption.
- Backed by Instance Store – The root device for an instance launched from the AMI is an instance store volume created from a template stored in S3.
- You can copy AMIs to different regions.
- Recycle Bin
- You can restore deleted AMIs using a recycle bin.
- You can set lock retention rules to protect against modifications and deletions.
- Check the timestamp to see when your AMI was last used to launch an instance.
- By default, a public AMI is deprecated after 2-years from the creation date.
- In the EC2 console, public AMIs owned by Amazon or a verified Amazon partner is marked as the verified provider.
- When an AMI changes state, an event is automatically generated, and you can use Amazon EventBridge to detect and respond to these events.
- With UEFI Secure Boot, you can ensure that an instance only boots software signed with cryptographic keys.
- You can configure an AMI to use Instance Metadata Service Version 2 (IMDSv2) when requesting instance metadata.
- If an AMI has been shared with your AWS account, you can remove your account from the AMI’s launch permissions.
Amazon EC2 Image Builder
- A fully managed AWS service that automates the creation, management, and deployment of your Amazon Machine Images (AMIs)
- The AWS Management Console, AWS Command Line Interface, or AWS APIs can be used to create custom images in your AWS account.
- You own the customized images that Image Builder creates in your account, and you can configure pipelines to automate updates and system patching for the images in your AWS account.
- Amazon EC2 Image Builder also provides a stand-alone command to create an AMI with the configuration resources that you have defined.
AWS EC2 Pricing Models and Options
Amazon Elastic Compute Cloud (EC2) offers a range of pricing models and options to cater to your specific needs. Understanding these options is crucial for optimizing costs and resource allocation in your AWS infrastructure. In this guide, we’ll explore the key pricing models and options available with AWS EC2.
On-Demand Instances
With On-Demand Instances, you pay for the compute capacity you use, with no long-term commitments or upfront payments required. This flexible pricing model allows you to scale your resources on-demand, paying by the second for instances in use.
Reserved Instances (RIs)
Reserved Instances provide significant cost savings for applications with predictable workloads. RIs require a one-time, upfront payment for a one- or three-year term, resulting in a considerably lower hourly rate for these instances. There are two classes of RIs:
Standard RIs: These offer the highest discount and are suitable for stable workloads. While some attributes can be modified during the term, they cannot be sold in the Reserved Instance Marketplace.
Convertible RIs: While offering a lower discount than Standard RIs, Convertible RIs provide flexibility. You can exchange them for other Convertible RIs with different attributes, except they cannot be sold in the Reserved Instance Marketplace.
Choosing the Right RI
When selecting an RI, consider the terms (one year or three years) and the average discount off On-Demand pricing (40% for one year and 60% for three years for Standard RIs). Convertible RIs offer discounts of 31% for one year and 54% for three years.
Availability Zone Flexibility
RIs differ in their ability to change Availability Zone and instance size (for Linux OS) during the term. Standard RIs provide this flexibility, whereas Convertible RIs offer more extensive changes, including instance families, operating systems, tenancy, and payment options.
Spot Instances
Spot Instances offer substantial cost savings, with discounts of up to 90% compared to On-Demand prices. They are ideal for workloads with flexible start and end times.
Spot Blocks: These Spot Instances have defined durations and are not interrupted during their run, making them suitable for tasks such as batch processing, encoding, rendering, and data analysis.
Spot Fleet: A collection of Spot Instances and optionally On-Demand Instances, managed by AWS to meet your target capacity. Spot Fleet attempts to fulfill Spot Instance requests if the specified price exceeds the current Spot price.
Spot Capacity Pool: A set of unused EC2 instances with the same characteristics, including instance type, OS, Availability Zone, and network platform.
EC2 Dedicated Hosts and Instances
Dedicated Hosts: Pay for a dedicated physical host to run your instances exclusively. You can bring your existing per-socket, per-core, or per-VM software licenses to reduce costs.
Dedicated Instances: Pay hourly for instances running on single-tenant hardware.
On-Demand Capacity Reservations
Reserve capacity for your EC2 instances in a specific Availability Zone without the need for long-term commitments. Specify the Availability Zone, the number of instances, and instance attributes.
Capacity Reservations and Savings Plans
Your Savings Plans and regional Reserved Instances can be applied to capacity reservations to receive discounts. Without these, your capacity reservations do not have billing discounts.
Data Transfer Charges
It’s essential to be aware of data transfer charges, particularly when copying Amazon Machine Images (AMIs) between regions. Data transfer between instances in different regions is subject to specific charges as well.
Elastic IP Address Charges
AWS imposes a small hourly charge for Elastic IP addresses that are not associated with running instances, stopped instances, or unattached network interfaces. Additional Elastic IP addresses associated with an instance also incur charges.
In summary, understanding AWS EC2 pricing models and options is crucial for optimizing costs and resources in your AWS environment. Whether you choose On-Demand Instances, Reserved Instances, Spot Instances, or other EC2 offerings, align your selection with your workload requirements and budget to maximize the value of your AWS investment.