Complete guide to Elastic Compute Cloud (EC2)
Introduction:
The ultimate focus of a traditional data center/server room is its precious servers. But, to make those servers useful, you’ll need to add racks, power supplies, cabling, switches, firewalls, and cooling. AWS’s Elastic Compute Cloud (EC2) is designed to replicate the data center/server room experience as closely as possible. At the center of it all is the Elastic Compute Cloud virtual server, known as an instance. But, like the local server room I just described, EC2 provides a range of tools meant to support and enhance your instance’s operations. This chapter will explore the tools and practices used to fully leverage the power of the EC2 ecosystem, including the following:
- Provisioning an EC2 instance with the right hardware resources for your project
- Configuring the right base operating system for your application needs
- Building a secure and effective network environment for your instance
- Adding scripts to run as the instance boots to support (or start) your application
- Choosing the best EC2 pricing model for your needs
- Understanding how to manage and leverage the EC2 instance lifecycle
- Choosing the right storage drive type for your needs
- Securing your EC2 resources using key pairs, security groups, and Identity and Access Management (IAM) roles
- Accessing your instance as an administrator or end-user client
EC2 Instances:
An EC2 instance, although virtualized, operates similarly to a physical server. It has access to storage, memory, and a network interface, with a fresh operating system installed. Users can customize the hardware resources, operating system, and software stack of the instance based on their requirements. Let’s explore how these features function.
Provisioning Your Instance:
Before launching your instance, you set up the operating system, software stack, hardware specifications (CPU, memory, storage, and network performance), and environment. The chosen Amazon Machine Image (AMI) defines the operating system, while the instance type determines the hardware configuration.
EC2 Amazon Machine Images:
An AMI serves as a template specifying the operating system and application software to include on the root data volume of an EC2 instance upon launch. There are four types of AMIs available.
Amazon Quick Start AMIs: Amazon Quick Start images are prominently displayed at the beginning of the instance launch process in the AWS console. These popular AMIs offer various releases of Linux or Windows Server OSs, along with specialty images for tasks like deep learning and database operations. They are regularly updated and officially supported by AWS.
AWS Marketplace AMIs:
AMIs from the AWS Marketplace are official, production-ready images provided and supported by industry vendors like SAP and Cisco.
Community AMIs:
The Community AMIs encompass over 100,000 images, often created and managed by independent vendors to address specific needs. This extensive catalog is valuable for those seeking a customized combination of software resources for their applications.
Instance Types:
AWS assigns hardware resources to your instances based on the instance type or hardware profile you select, which should align with your planned workload. It’s essential to strike a balance between cost and the required compute power, memory, and storage space. Ideally, you’ll find an instance type that meets both your application requirements and budget constraints.
If your needs change over time, you can easily switch to a different instance type by stopping the instance, editing its type, and restarting it. Currently, there are over 75 instance types grouped into five families, with AWS frequently updating their selection. For the most recent collection, refer to the AWS website at https://aws.amazon.com/ec2/instance-types/.
EC2 instance type family and their top-level designations:
Instance Type Family | Types |
General purpose | T3, T2, M5, M4 |
Compute optimized | C5, C4 |
Memory optimized | X1e, X1, R5, R4, z1d |
Accelerated computing | P3, P2, G3, F1 |
Storage optimized | H1, I3, D2 |
General Purpose:
The General-Purpose family, comprising T3, T2, M5, and M4 types, aims to offer a balanced mix of compute, memory, and network resources. For example, T2 instances range from the t2.nano with one vCPU and half a gigabyte of memory to the t2.2xlarge with eight vCPUs and 32 GB of memory. The t2.micro, eligible for the Free Tier, is often suitable for experimentation, but it can also be used for light-use websites and development-related services.
T2 instances are burstable, allowing accumulation of CPU credits during low utilization periods for enhanced performance during peak demand. On the other hand, M5 and M4 instances are recommended for many small and midsize datacentric operations. Unlike T2 instances, some M* instances come with their own instance storage drives attached to the host server. M5 types range from m5.large (2 vCPUs and 6 GB of memory) to the formidable m5d.24xlarge (96 vCPUs and 382 GB of memory).
Compute Optimized:
For demanding web servers and high-performance machine learning tasks, the Compute Optimized family offers options like the C5 and C4 types. C5 machines, ranging from c5.large to c5d.18xlarge, provide up to 3.5 GHz of processor speed and robust network bandwidth.
Memory Optimized:
Memory Optimized instances are ideal for intensive database, data analysis, and caching tasks. Types like X1e, X1, and R4 offer up to 3 terabytes of DRAM-based memory and low-latency SSD storage volumes.
Accelerated Computing:
Within the Accelerated Computing group, types like P3, P2, G3, and F1 offer higher-performing general-purpose graphics processing unit (GPGPU) capabilities. These instances utilize advanced NVIDIA GPUs or, in the case of F1, a Xilinx Virtex UltraScale+ field-programmable gate array (FPGA). They are suitable for demanding workloads such as 3D visualizations, financial analysis, and computational fluid dynamics.
Storage Optimized:
Types like H1, I3, and D2 feature large, low-latency instance storage volumes, with capacities reaching up to 16 TB or even 48 TB for D2 instances. These instances are well-suited for distributed file systems and heavy-duty data processing applications.
Configuring an Environment for Your Instance:
Choosing the location for your EC2 instance is crucial, involving three key details: geographic region, virtual private cloud (VPC), and tenancy model. AWS Regions are distributed worldwide, so launching your EC2 instance in the region closest to your customers or compliant with legal requirements is essential. You can manage EC2 resources only within their designated region, which can be set in the console or through AWS CLI configuration. Keep in mind that costs and functionality may vary between regions, so consulting up-to-date documentation is advisable.
VPCs:
Choosing the location for your EC2 instance is crucial, involving three key details: geographic region, virtual private cloud (VPC), and tenancy model. AWS Regions are distributed worldwide, so launching your EC2 instance in the region closest to your customers or compliant with legal requirements is essential. You can manage Elastic Compute Cloud resources only within their designated region, which can be set in the console or through AWS CLI configuration. Keep in mind that costs and functionality may vary between regions, so consulting up-to-date documentation is advisable.
Adding a simple VPC that doesn’t incorporate a NAT gateway (https://community.aws/content/2b5hpna7zvZdEgaUOeE0xLN95OT/vpc-endpoints-an-alternative-to-nat-gateway) or
VPN access (https://docs .aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_VPN.html) won’t cost you anything. You’ll learn much more about all this in Chapter 4, “Amazon Virtual Private Cloud.”
Interview Questions:
- How does virtualization contribute to the efficiency of cloud computing?
- What are the core service categories offered by AWS?
- Can you explain the concept of serverless architectures and its relevance in cloud computing?
- What is the significance of the AWS Shared Responsibility Model in cloud security?
- How do you determine the optimal geographic region for launching an EC2 instance?
- What are the key factors to consider when selecting an instance type family for an EC2 instance?
- How does Auto Scaling help in managing Elastic Compute Cloud (EC2) instances based on demand?
- What are the benefits of using a virtual private cloud (VPC) in AWS infrastructure?
- Can you explain the concept of AWS Marketplace AMIs and their relevance in instance provisioning?
- How does the AWS Shared Responsibility Model apply to the security and operation of installed operating systems within the cloud?
Lab Scenario for Kloud Course Academy: As a solutions architect at Kloud Course Academy, you are tasked with setting up a multi-VPC infrastructure for a development environment. The goal is to create isolated environments for different project stages, ensuring efficient resource utilization and security. You will need to configure VPCs, select appropriate instance types, and consider geographic regions to optimize performance and cost-effectiveness for the development projects