Choosing the Right AWS EC2 Instance: Avoiding Common Pitfalls
Tags: aws, ec2, cloudoperati, sre
Published: 2023-10-27 22:56:14

AWS provides an array of compute options to cater to the diverse needs of workloads. From virtual servers and container management services to serverless compute, AWS offers a multitude of choices. In this blog post, I'll delve into one of the most foundational and versatile options: **Amazon EC2 (Elastic Compute Cloud)**.

Everyone’s AWS journey usually start with EC2 and whether your looking to deploy a simple application or a complex enterprise application, EC2 will play a crucial role. 

**Be clear when to use what**

Amazon EC2 instances are categorized into several families, each tailored to specific use cases. These categories will help you to identify when to use what type of instances. It’s very important to be clear of your requirement when you’re starting this.

- General Purpose - For hosting a WordPress blog for a personal website.
- Burstable - For developing and testing code for a new mobile app.
- Compute Optimized - For running complex financial calculations for a stock trading platform.
- Memory Optimized - For operating a large-scale e-commerce website with a high-speed product catalog.
- Accelerated Computing - For training a deep learning model for image recognition in healthcare applications.
- Storage Optimized - For storing and serving a vast library of multimedia content for an online streaming service.
- HPC Optimized - For conducting complex weather simulations for meteorological research.
- EC2 instances offer an impressive array of capabilities, allowing you to fine-tune your cloud infrastructure.

Once your clear with your requirement and what is your purpose, AWS offers array of configuration option to optimize the workloads.

**Instance Configuration:**

AWS EC2 provides a wide range of configuration options, allowing users to select instance types, family, size and many option to meet their specific workload needs.

- **Instance Type**: Select from t1.micro to z1d.metal based on your workload's resource needs.
- **Instance Family**: Choose from instance families like t1 to z1d to align with workload characteristics.
- **Instance Size**: Pick the appropriate size, ranging from micro and nano to metal, to match workload requirements.
- **Hypervisor (Xen and Nitro)**: Decide between Xen and Nitro hypervisors for virtualization to meet performance and security needs.
- **Auto Recovery Support**: Enable automatic recovery to maintain high availability in case of system failures.
- **Supported Root Device Types**: Choose between EBS or instance store to suit your storage and data persistence requirements.
- **Dedicated Host Support**: Utilize dedicated hosts for isolated and compliant workloads, ensuring no shared resources.
- **On-Demand Hibernation Support**: Enable hibernation for instances to save state and quickly resume workloads as needed.
- **Burstable Performance Support**: Use burstable instances to adapt to variable workloads by bursting CPU performance when necessary.

**Compute Characteristics:**

AWS EC2 offers free-tier eligibility, free trials, bare-metal options, customizable vCPUs, architecture, cores, threads, clock speed, memory, and access to the latest generation for varied workload needs.

- **Free-Tier Eligible**: Leverage free-tier eligibility for cost-effective testing and small-scale workloads.
- **Free Trial Available**: Benefit from a free trial to evaluate and experiment with AWS EC2 instances.
- **Bare Metal**: Consider bare-metal instances for workloads that require direct hardware access.
- **vCPUs (1 to 48)**: Select the appropriate number of virtual CPUs based on workload requirements.
- **Architecture (i386 to x86_64)**: Choose between 32-bit (i386) and 64-bit (x86_64) architectures as needed.
- **Cores (1 to 224)**: Configure the number of physical cores to match computational demands.
- **Threads per Core (1 to 2)**: Specify the number of threads per core for efficient multi-threading.
- **Sustained Clock Speed (GHz, 2.1 to 4.5)**: Match clock speed to workload performance requirements.
- **Memory (GiB, up to 24576)**: Allocate memory according to your workload's memory requirements.
- **Current Generation**: Consider the current generation of instances for the latest features and capabilities.

**Networking Options:**

AWS EC2's networking options allow you to optimize workloads with Availability Zones, enhance EBS performance, select appropriate network characteristics, support ENA for increased capabilities, configure network interfaces, use IPv4 and IPv6, choose placement group strategies, and access ENA Express for advanced features.

- **Availability Zones**: Utilize availability zones to distribute and replicate workloads for high availability.
- **EBS Optimization Support**: Optimize EBS for enhanced performance and throughput.
- **Network Performance**: Select instances with the appropriate network performance characteristics.
- **ENA Support (up to 80)**: Benefit from Enhanced Networking Adapter (ENA) support for increased network capabilities.
- **Maximum Number of Network Interfaces**: Ensure the required number of network interfaces for your workload.
- **IPv4 and IPv6 Addresses**: Configure IPv4 and IPv6 addresses per interface as necessary.
- **IPv6 Support**: Enable IPv6 for workloads that require it.
- **Supported Placement Group Strategies**: Choose between placement group strategies like cluster, partitioned, or spread based on your workload's placement requirements.
- **ENA Express Support**: Utilize ENA Express for advanced network features.

**Storage Configurations:**

AWS EC2's storage configurations offer the flexibility to allocate capacity, use local instance storage, select between HDD and SSD storage, adjust disk count, and enable EBS encryption for data security and compliance, allowing you to customize workloads to your specific needs.

- **Storage (GB, up to 335535)**: Allocate storage capacity to meet your workload's data storage needs.
- Local Instance Storage: Consider instances with local storage for certain types of workloads.
- **Storage Type (HDD or SSD)**: Choose between HDD and SSD storage to balance performance and cost.
- **Storage Disk Count (up to 24)**: Configure the number of storage disks as required.
- **EBS Encryption Support**: Enable EBS encryption for data security and compliance.

**Accelerator Options:**

AWS EC2's accelerator options, including GPUs and FPGAs, empower you to select the right hardware for accelerated computing, matching GPU and FPGA manufacturers to your use cases, providing enhanced performance and compatibility for your workloads. Understanding these specifications ensures informed decisions for your unique requirements.

- **GPUs (up to 16)**: Choose GPUs based on workload requirements for accelerated computing.
- **GPU Manufacturer**: Select the appropriate GPU manufacturer for compatibility and performance.
- **FPGAs (up to 8)**: Use FPGAs for specialized hardware acceleration as needed.
- **FPGA Manufacturer**: Choose the FPGA manufacturer that suits your workload's acceleration requirements.

EC2 instances offer unmatched flexibility, and understanding these specifications will help you make informed decisions for your workloads.

**Finally AWS Graviton**

AWS Graviton processors deliver excellent price performance, especially for Linux-based workloads. They support multiple Linux operating systems but are not available for Windows. Graviton2, the second-generation processor, offers a 40% improvement in price performance over comparable x86-based instances, while Graviton3 takes performance to new heights, offering up to three times better performance than Graviton2.

**Let's apply what we've discussed earlier in a practical example:**

We're going to set up an Apache Web server and host a simple "Hello World" page on an EC2 instance. While this is supper easy, it covers what we discussed above. Here's what you'll need to do when launching an instance:

- Provide a Name and Tags for your instance.
- Choose your operating system (OS).
- Based on your OS choice, select the appropriate Amazon Machine Image (AMI).
- Pick the desired Instance type that suits your requirements. This is where you can select an instance type that meets your computing, memory, networking, or storage needs.
 
Following caught my eye - AWS offers Amazon EC2 t4g.small instances powered by AWS Graviton2 processors free for up to 750 hours per month until Dec 31, 2023.

- Select an existing Key Pair or create a new one for secure access to your instance.
- Set up your network settings, which includes creating or selecting a security group to control SSH, HTTP, and HTTPS traffic.
- Configure the storage settings to allocate the required amount of storage for your instance.

These are the essential steps to get started. Once you've completed these, you can go into more advanced settings as needed.Few of them are :

- **Instance auto recovery**: Automatically restarts your EC2 instance if it fails due to a system issue.
- **Shutdown behavior**: Determines whether the instance should stop or terminate when you initiate a shutdown from within the instance.
- **Hibernate behavior**: Allows you to put your instance in a hibernation state, saving its state and allowing you to resume it later.
- **Termination protection**: Prevents accidental termination of an instance to avoid data loss or disruptions.
- **CloudWatch monitoring**: Enables monitoring of your instance's performance and resource utilization through Amazon CloudWatch.
- **Elastic GPU**: Provides additional graphics processing power for your instance, useful for graphics-intensive applications.
- **Credit specification**: Relates to T2 and T3 instance types, determining the baseline performance and CPU credits you receive.
- **Purchasing options like Stop instance**s: Allows you to save costs by stopping instances and restarting them later (EC2 instance stop/start feature).
- **Capacity reservations**: Reserves capacity for your instances to ensure availability and performance.
- **Tenancy**: Specifies whether your instance runs on shared hardware or dedicated hardware, providing isolation.
- **User data**: Lets you input custom data or scripts to configure your instance during launch.
 
In conclusion, selecting the right AWS EC2 instance is crucial for optimizing performance and controlling costs in the cloud. By understanding the available categories, capabilities, and options, and by considering your specific requirements, you can make well-informed choices that align perfectly with your workloads. AWS EC2's flexibility and scalability ensure that you can tailor your cloud infrastructure to suit your needs precisely.

Based on my experience, some key EC2 pitfalls to watch out for include:

- **Over-Provisioning**: It's common to select instances with more power and resources than needed, leading to higher costs and wasted resources.
- **Under-Provisioning**: Choosing instances with insufficient resources can result in performance issues, slow response times, and a poor user experience.
- **Ignoring Pricing Models**: Not considering different pricing options can lead to unnecessary expenses. For example, using Reserved Instances for steady workloads can save you money.
- **Not Considering Instance Types**: Choosing the wrong instance type for your workload can lead to inefficiencies. Be sure to match the instance type to your application's requirements.
- **Lack of Monitoring and Optimization**: Failing to monitor and optimize your EC2 instances can result in underutilization or overutilization, impacting both performance and costs. Use AWS tools for better management.

If you want to learn more about EC2 and get detailed information, I suggest you start your journey by visiting https://aws.amazon.com/ec2/. This is the best place to begin learning about EC2.