Activity 13: What is AWS EC2?

Introduction

Amazon Elastic Compute Cloud (Amazon EC2) is one of the core services of Amazon Web Services (AWS). It provides scalable, resizable computing capacity in the cloud, allowing users to launch virtual servers (called instances) to run applications, workloads, or services without needing to invest in physical hardware. EC2 is designed to make web-scale computing easier and more cost-effective for developers and businesses.

EC2 instances can be configured with different hardware specifications such as CPU, memory, storage, and network capacity, making it suitable for a wide range of use cases, from simple websites to complex machine learning models.


Key Features of Amazon EC2

1. Scalability

EC2 allows users to scale their computing power both vertically (changing the size of an instance) and horizontally (adding more instances). This means that you can easily adjust your resources to meet the changing demands of your application or workload.

  • Auto Scaling: Auto Scaling helps you automatically increase or decrease the number of EC2 instances in response to traffic demand. This ensures that your application can handle increased loads during peak times and save costs during low-traffic periods.

2. Instance Types

EC2 offers a wide variety of instance types, each optimized for different purposes, allowing users to choose the most appropriate instance for their needs.

  • General Purpose Instances: These instances provide a balance of compute, memory, and networking resources. Examples include the t3 and m5 families.

  • Compute Optimized Instances: These instances are ideal for CPU-intensive tasks, such as high-performance computing (HPC). Examples include the c5 family.

  • Memory Optimized Instances: These instances are designed for memory-intensive tasks such as large in-memory databases. Examples include the r5 family.

  • Storage Optimized Instances: These instances are designed for high I/O operations, ideal for applications like databases or big data processing. Examples include the i3 family.

3. Elasticity

EC2 offers elastic compute capacity, which means you can quickly launch instances and adjust resources based on your application’s needs. You can start, stop, and terminate instances based on demand, ensuring efficient resource usage and cost management.

4. Global Reach with Availability Zones

AWS EC2 instances are hosted in multiple regions worldwide, and each region consists of several Availability Zones (AZs). Availability Zones are isolated locations within a region that provide redundancy and minimize the risk of failure, ensuring high availability for your applications.

  • Regions: Physical locations worldwide where AWS data centers are located.

  • Availability Zones: Distinct locations within regions that are engineered to be isolated from failures in other Availability Zones.

5. Security

Amazon EC2 integrates with AWS Identity and Access Management (IAM), which allows you to control who can start, stop, or modify your instances. Security groups (virtual firewalls) control inbound and outbound traffic to EC2 instances, ensuring your applications remain secure.

  • Key Pairs: EC2 uses key pairs (public and private key encryption) to secure the login to instances.

  • Virtual Private Cloud (VPC): EC2 instances are launched in a VPC, giving you full control over the networking aspects, such as IP ranges, subnets, and routing.

6. Pay-as-You-Go Pricing

EC2 uses a pay-as-you-go pricing model, which means you only pay for the compute capacity you use. AWS provides different purchasing models for EC2 instances:

  • On-Demand Instances: Pay for compute capacity by the hour or second with no long-term commitments. Suitable for short-term workloads or unpredictable usage.

  • Reserved Instances: Commit to using an instance for a 1- or 3-year term in exchange for significant discounts. Best for steady-state or predictable usage.

  • Spot Instances: Purchase unused EC2 capacity at discounted rates, with the risk that AWS can reclaim the instances when needed. Ideal for flexible, fault-tolerant workloads.

  • Savings Plans: Flexible pricing model offering lower prices in exchange for a commitment to a consistent amount of usage over a 1- or 3-year term.


EC2 Architecture

Amazon EC2 operates as part of a broader AWS ecosystem and is highly customizable. When you launch an EC2 instance, you define several parameters:

1. Amazon Machine Image (AMI)

An AMI is a template used to create an instance. It contains the operating system, application server, and applications that will run on the instance. AWS provides a wide range of pre-built AMIs (for Windows, Linux, etc.), or you can create your own custom AMI.

2. Instance Type

The instance type defines the hardware specifications of the virtual machine, including the number of CPUs, amount of memory (RAM), storage options, and network capacity.

3. Security Groups

Security groups act as virtual firewalls for EC2 instances. They control inbound and outbound traffic at the instance level, allowing you to define rules for what type of traffic can access your instances.

  • Example: You might only allow HTTP and HTTPS traffic to a web server, or limit SSH access to certain IP addresses.

4. Elastic Block Store (EBS)

Amazon EBS provides persistent block-level storage that can be attached to EC2 instances. This allows you to store and retrieve data even after the instance is terminated.

5. Elastic IP Addresses

An Elastic IP is a static, public IP address that can be associated with an EC2 instance. This allows you to ensure your instance has a fixed IP address even when it's stopped and started again.


Common Use Cases for EC2

1. Web Hosting

EC2 is widely used to host websites and web applications, as it provides a flexible, scalable environment for running web servers, databases, and application servers.

  • Example: Deploying a WordPress website using a pre-built Linux AMI with Apache and MySQL.

2. Batch Processing

EC2 can be used to run batch processing jobs, such as video rendering or scientific computations, by scaling out a fleet of instances that process data in parallel.

  • Example: Running computational workloads for bioinformatics analysis.

3. High-Performance Computing (HPC)

Compute-optimized EC2 instances are ideal for high-performance computing tasks, such as simulations, financial modeling, or big data analytics.

4. Development and Testing

EC2 is often used for creating test environments for developers. It allows developers to quickly spin up instances, test their applications in different environments, and tear down the instances when done.

5. Disaster Recovery

Many organizations use EC2 as part of their disaster recovery strategy by replicating workloads and backing up data in another AWS region. In the event of a disaster, EC2 instances can be quickly launched to restore operations.


Benefits of Using Amazon EC2

1. Flexibility

EC2 offers a high level of customization. You can choose the operating system, networking setup, and instance size that suits your application needs.

2. Elasticity

The ability to quickly scale up or down means you never need to over-provision or under-provision your infrastructure. EC2 can automatically respond to changes in demand.

3. Cost-Efficiency

EC2’s pricing models (on-demand, reserved, and spot instances) allow businesses to choose the most cost-effective way to run their workloads. Additionally, you only pay for what you use, reducing waste.

4. Global Reach

With AWS regions and availability zones around the world, EC2 ensures low-latency access to your applications and can help comply with data residency regulations by hosting workloads in specific regions.

5. Security

EC2 provides a high level of security through key pairs, security groups, IAM roles, and encryption, making it suitable for sensitive applications and data.


How to Launch an EC2 Instance (Step-by-Step)

Step 1: Log in to AWS Console

Step 2: Navigate to EC2 Dashboard

  • From the AWS console, search for EC2 and navigate to the EC2 dashboard.

Step 3: Choose an AMI

  • Click "Launch Instance" and choose an Amazon Machine Image (AMI). You can choose a pre-configured Linux or Windows AMI or create a custom one.

Step 4: Select Instance Type

  • Choose an instance type that best fits your use case. You can select from the general-purpose, compute-optimized, memory-optimized, or storage-optimized instance families.

Step 5: Configure Instance Details

  • Configure instance details, such as the number of instances, network settings (VPC, subnet), and IAM role.

Step 6: Add Storage

  • Specify the size and type of storage (EBS volumes) to attach to your instance.

Step 7: Configure Security Groups

  • Set up security groups to control the traffic to and from your instance.

Step 8: Review and Launch

  • Review all your configurations, then click Launch. Assign a key pair for SSH access and wait for the instance to be initialized.

Resources

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html

https://www.w3schools.com/whatis/whatis_aws_ec2.asp