0% found this document useful (0 votes)
23 views14 pages

1 - Ec2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views14 pages

1 - Ec2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Amazon EC2 (Elastic Compute Cloud) Detailed Write-Up

REFERENCE LINKS
Amazon EC2 - Cloud Compute Capacity - AWS
Amazon EC2 Documentation

Introduction to Cloud Computing


Before diving into Amazon EC2, it’s essential to understand the concept of cloud computing. Cloud
computing allows users to access and store data and applications on remote servers, rather than on local
computers. This technology provides several benefits, including cost efficiency, scalability, and ease of
access.

What is Amazon EC2?


Amazon EC2 (Elastic Compute Cloud) is a web service provided by Amazon Web Services (AWS) that
offers resizable compute capacity in the cloud. It allows users to rent virtual servers, known as instances,
to run their applications. This flexibility means you can scale up or down as your computing needs
change, paying only for the capacity you use.

Key Concepts of Amazon EC2


1. Instances: Virtual servers that run applications.
2. Amazon Machine Images (AMIs): Pre-configured templates for your instances, including the
operating system and software.
3. Instance Types: Different configurations of CPU, memory, storage, and networking capacity to
suit various use cases.
4. Regions and Availability Zones: Geographic locations where AWS data centers are located.
Each region contains multiple isolated locations known as Availability Zones.
5. Elastic IP Addresses: Static IP addresses designed for dynamic cloud computing.
6. Security Groups: Virtual firewalls that control the traffic for one or more instances.
7. Elastic Block Store (EBS): Persistent block storage volumes for use with Amazon EC2
instances.

Getting Started with Amazon EC2


To use Amazon EC2, you need an AWS account. Here’s a step-by-step guide to launching your first EC2
instance:

1. Sign Up for AWS: Go to the AWS website and sign up for an account. AWS offers a free tier that
includes limited usage of EC2 instances.
2. Open the EC2 Dashboard: Once logged in, navigate to the EC2 Dashboard from the AWS
Management Console.
3. Launch an Instance:
○ Choose an Amazon Machine Image (AMI): Select a pre-configured template (e.g.,
Ubuntu, Windows Server).
○ Choose an Instance Type: Select the hardware configuration. For beginners, the
t2.micro instance type is a good start as it's free-tier eligible.
○ Configure Instance Details: Set the number of instances, network settings, and more.
○ Add Storage: Define the size and type of storage for your instance.
○ Add Tags: Assign metadata to your instance for easier management.
○ Configure Security Group: Set up firewall rules to allow specific traffic (e.g., SSH for
Linux, RDP for Windows).
○ Review and Launch: Review your settings and launch the instance. You’ll need to
create or select an existing key pair for SSH access.
4. Connect to Your Instance: Once the instance is running, you can connect to it using SSH (for
Linux instances) or RDP (for Windows instances). AWS provides a “Connect” button in the
console with instructions.

EC2 Instance Types


Amazon EC2 offers a variety of instance types, grouped into categories based on their intended use
cases:

1. General Purpose: Balanced compute, memory, and networking resources. Ideal for web servers,
development environments. (e.g., t2, t3, m5)
2. Compute Optimized: High CPU performance. Suitable for compute-intensive applications. (e.g.,
c5, c6g)
3. Memory Optimized: Designed for memory-intensive tasks. Ideal for large databases and
memory analytics. (e.g., r5, x1)
4. Storage Optimized: High, sequential read and write access to large data sets. Suitable for big
data and data warehousing. (e.g., i3, d2)
5. Accelerated Computing: Use hardware accelerators, or co-processors, to perform functions
such as floating-point number calculations, graphics processing, or data pattern matching. (e.g.,
p3, g4)

Benefits of Using Amazon EC2


1. Scalability: Easily scale your compute capacity up or down according to your needs.
2. Cost Efficiency: Pay only for what you use with options for on-demand, reserved, and spot
instances.
3. Flexibility: Wide variety of instance types and AMIs to choose from, supporting multiple
operating systems and applications.
4. Reliability: Built on a highly reliable infrastructure, with multiple geographic regions and
Availability Zones.
5. Security: Includes numerous security features, such as security groups, IAM roles, and
encryption.

Pricing Models
1. On-Demand Instances: Pay for compute capacity by the hour or second with no long-term
commitments.
2. Reserved Instances: Commit to using EC2 for a 1- or 3-year term to get a significant discount.
3. Spot Instances: Bid on unused EC2 capacity at reduced rates. Suitable for fault-tolerant and
flexible applications.
4. Savings Plans: Flexible pricing model offering lower prices in exchange for a commitment to a
consistent amount of usage (measured in $/hour) for a 1- or 3-year term.

Use Cases
1. Web Hosting: Host websites and web applications with the ability to scale resources based on
traffic.
2. Big Data: Process large datasets efficiently with high-performance computing resources.
3. Machine Learning: Train and deploy machine learning models using powerful GPU instances.
4. Game Development: Develop and host game servers with scalable compute resources.
5. Development and Testing: Set up isolated development and testing environments quickly and
cost-effectively.

Conclusion
Amazon EC2 is a powerful and flexible cloud computing service that provides scalable and resizable
compute capacity. It is suitable for a wide range of applications, from simple web hosting to complex
machine learning workloads. Understanding the basic concepts and features of EC2 can help you
leverage the full potential of cloud computing in your projects. Whether you are developing software,
processing big data, or running enterprise applications, EC2 provides the tools and resources you need to
succeed.
Response generated on 25May2024

Detailed Write-Up for Module 1: Amazon EC2 (Elastic


Compute Cloud)
Lecture 1: Introduction to Amazon EC2
Introduction to EC2

Definition: Amazon Elastic Compute Cloud (EC2) is a web service provided by Amazon Web Services
(AWS) that offers scalable and resizable compute capacity in the cloud. It allows users to launch and
manage virtual servers, known as instances, to run applications and perform various computing tasks.

Benefits:

● Scalability: Easily scale up or down based on demand. EC2 instances can be launched or
terminated quickly, allowing for dynamic resource management.
● Cost Efficiency: Pay only for the compute capacity you use. With various pricing models like On-
Demand, Reserved, and Spot Instances, users can optimize costs.
● Flexibility: Wide variety of instance types and configurations to choose from, supporting different
operating systems and software packages.
● Reliability: Built on a highly reliable infrastructure with multiple geographic regions and
Availability Zones, ensuring high availability and fault tolerance.

Key Concepts

Instances: Virtual servers used to run applications.

● Types: Instances are categorized based on their intended use cases and hardware
configurations:
○ General Purpose: Balanced CPU, memory, and network resources. Ideal for a variety of
applications.
○ Compute Optimized: High-performance processors for compute-intensive tasks.
○ Memory Optimized: Large memory capacities for memory-intensive applications.
○ Storage Optimized: High, sequential read and write access to large data sets.
○ Accelerated Computing: Use of hardware accelerators like GPUs.

Amazon Machine Images (AMIs): Pre-configured templates for your instances, including the operating
system, application server, and applications. AMIs provide the information required to launch an instance.

Instance Types: Different configurations of CPU, memory, storage, and networking capacity tailored for
specific workloads.

Regions and Availability Zones: AWS data centers are organized into regions (geographic locations)
and Availability Zones (isolated locations within each region). Using multiple Availability Zones improves
fault tolerance and disaster recovery.

Security Groups: Virtual firewalls that control the inbound and outbound traffic to instances. Security
groups allow you to define rules for which IP address ranges can access your instances.
Demo: Launching Your First EC2 Instance

Step-by-Step Guide:

1. Select an AMI: Choose a pre-configured template (e.g., Amazon Linux 2).


2. Choose an Instance Type: Select the hardware configuration (e.g., t2.micro).
3. Configure Instance Details: Set the number of instances, network settings, etc.
4. Add Storage: Define the size and type of storage.
5. Configure Security Group: Set up firewall rules to allow specific traffic (e.g., SSH for Linux).
6. Review and Launch: Review your settings and launch the instance.

Connecting to the Instance:

● SSH (for Linux): Use an SSH client to connect to your instance.


● RDP (for Windows): Use Remote Desktop Protocol to connect to your instance.

Q&A Session:

● Address any questions and clarify doubts from the students.

Homework:

● Explore the AWS Management Console and familiarize yourself with the EC2 dashboard.
● Read the AWS documentation on EC2: Amazon EC2 Documentation.

Lecture 2: Deep Dive into EC2 Features


Amazon Elastic Block Store (EBS)

Definition: High-performance block storage service designed for use with EC2 instances. EBS volumes
provide persistent storage that remains available even when the instance is stopped or terminated.

Types of EBS Volumes:

● General Purpose SSD (gp2, gp3): Balanced price and performance for a wide variety of
workloads.
● Provisioned IOPS SSD (io1, io2): High-performance storage for I/O-intensive applications like
databases.
● Throughput Optimized HDD (st1): Low-cost HDD for frequently accessed, throughput-intensive
workloads.
● Cold HDD (sc1): Lowest-cost HDD for infrequently accessed data.

Creating and Attaching EBS Volumes:

● How to create EBS volumes from the AWS Management Console.


● Attaching EBS volumes to an EC2 instance for additional storage.

Snapshots:

● Creating and managing EBS snapshots for backup and restore purposes.
● Snapshots are incremental, meaning that only the blocks that have changed since your last
snapshot are saved.

Elastic IP Addresses
Definition: Static IP addresses designed for dynamic cloud computing. An Elastic IP address is
associated with your AWS account and can be remapped to any instance in your account.

Benefits:

● Maintain a fixed IP address even when instances are stopped and restarted.
● Remap your Elastic IP address quickly to another instance in the event of an instance failure.

Allocating and Associating Elastic IPs:

● Allocating a new Elastic IP address from the AWS Management Console.


● Associating the Elastic IP address with an EC2 instance.

Auto Scaling

Definition: Auto Scaling automatically adjusts the number of EC2 instances in response to the demand
to maintain performance and minimize costs.

Components:

● Auto Scaling Groups: Manage the collection of EC2 instances.


● Scaling Policies: Define the conditions under which to add or remove instances.

Benefits:

● Ensures application availability by dynamically adding or removing instances based on demand.


● Helps reduce costs by scaling in when demand is low and scaling out when demand is high.

Load Balancing

Definition: Distributes incoming traffic across multiple EC2 instances, ensuring no single instance
becomes overloaded.

Types of Load Balancers:

● Application Load Balancer (ALB): Best suited for HTTP and HTTPS traffic. Provides advanced
request routing features.
● Network Load Balancer (NLB): Handles TCP, UDP, and TLS traffic. Best for performance and
low latency.
● Classic Load Balancer (CLB): Legacy load balancer, suitable for basic load balancing needs.

Configuring a Load Balancer:

● Setting up a load balancer to distribute traffic to EC2 instances.

Q&A Session:

● Address any questions and clarify doubts from the students.

Homework:

● Practice creating and managing EBS volumes and snapshots.


● Allocate and associate an Elastic IP to an EC2 instance.
● Set up an Auto Scaling group with a simple scaling policy.
● Configure a basic load balancer.

Lecture 3: Advanced EC2 Concepts and Best Practices


Advanced EC2 Concepts

Instance Purchasing Options:

● On-Demand Instances: Pay by the hour or second, with no long-term commitments. Ideal for
short-term, unpredictable workloads.
● Reserved Instances: Significant discount for committing to use EC2 for a 1 or 3-year term. Ideal
for steady-state or predictable usage.
● Spot Instances: Bid on unused EC2 capacity for lower costs. Ideal for flexible, interruptible
workloads.

Placement Groups:

● Cluster Placement Groups: Low-latency network performance within a single Availability Zone.
Best for tightly coupled node-to-node communication.
● Spread Placement Groups: Instances spread across underlying hardware to reduce the risk of
simultaneous failures. Best for critical applications.
● Partition Placement Groups: Instances divided into logical segments called partitions. Best for
large distributed and replicated workloads.

Elastic Fabric Adapter (EFA): Network device that you can attach to your Amazon EC2 instance to
accelerate High-Performance Computing (HPC) and machine learning applications.

Security Best Practices

● IAM Roles: Use IAM roles for EC2 instances to securely manage permissions.
● Regular Updates: Regularly update and patch your instances to protect against vulnerabilities.
● Security Groups and Network ACLs: Implement security groups and network ACLs to control
inbound and outbound traffic.
● Encryption: Encrypt data at rest using EBS encryption and in transit using SSL/TLS.
● Monitoring and Logging: Monitor and log activity using AWS CloudTrail and Amazon
CloudWatch.

Cost Optimization Strategies

● Right-Sizing: Right-size your instances based on workload requirements to avoid over-


provisioning.
● Use Reserved and Spot Instances: Use Reserved Instances for predictable workloads and
Spot Instances for flexible, interruptible workloads to save costs.
● Monitor Usage: Monitor and analyze your usage with AWS Cost Explorer and Trusted Advisor to
identify opportunities for cost optimization.
● Automate Instance Scheduling: Automate instance scheduling to stop instances during non-
peak hours and reduce costs.

Real-World Applications of EC2

● Hosting Scalable Web Applications: Use EC2 instances to host web applications that can
scale based on demand.
● Big Data Processing: Process large datasets with tools like Hadoop and Spark.
● Machine Learning: Train and deploy machine learning models on powerful GPU instances.
● High-Performance Computing (HPC): Run HPC workloads that require significant
computational power.

Case Studies

● Discuss real-world case studies of companies using EC2 to solve complex problems and optimize
their IT infrastructure.

Q&A Session:

● Address any questions and clarify doubts from the students.

Homework:

● Explore instance purchasing options and determine which best suits different use cases.
● Implement security best practices on your EC2 instances.
● Use AWS Cost Explorer to analyze your EC2 usage and identify opportunities for cost
optimization.

References and Further Reading


● Amazon EC2 Features
● Amazon EC2 Documentation
● AWS Security Best Practices
● AWS Cost Management

This detailed write-up provides a comprehensive understanding of Amazon EC2, its features, best
practices, and real-world applications

Load Balancing Explanation


Load Balancing in Amazon EC2
Introduction

Load balancing is essential for designing large-scale, high-availability applications. It helps distribute
incoming network traffic across multiple servers, ensuring no single server becomes a bottleneck. In the
context of Amazon Web Services (AWS), Elastic Load Balancing (ELB) automatically distributes incoming
application traffic across multiple EC2 instances, enhancing the availability and reliability of your
application.

Types of Load Balancers in AWS


Application Load Balancer (ALB)

The Application Load Balancer operates at the application layer (Layer 7) of the OSI model. It is designed
to handle HTTP and HTTPS traffic and provides advanced request routing based on the content of the
request.

Key Features:
● Content-based Routing: Routes requests based on the URL, host headers, HTTP headers, and
more.
● WebSocket Support: ALB supports WebSocket and HTTP/2 protocols.
● Security: Integration with AWS Certificate Manager (ACM) for SSL/TLS certificates, and AWS
WAF for web application firewall protection.

Network Load Balancer (NLB)

The Network Load Balancer operates at the transport layer (Layer 4). It is designed for handling TCP,
UDP, and TLS traffic, capable of processing millions of requests per second with low latency.

Key Features:

● High Performance: Suitable for applications that require ultra-low latency.


● Static IP Support: Provides a single static IP per Availability Zone for the load balancer.
● TLS Termination: Offloads the decryption/encryption of TLS traffic.

Classic Load Balancer (CLB)

The Classic Load Balancer operates at both the application and transport layers. It provides basic load
balancing across multiple EC2 instances and is suitable for applications built within the EC2-Classic
network.

Key Features:

● Simple Configuration: Easy to set up and manage.


● Hybrid Support: Supports both Layer 4 and Layer 7 load balancing.

Gateway Load Balancer (GWLB)

The Gateway Load Balancer operates at the network layer and is designed for deploying, scaling, and
managing virtual appliances such as firewalls, intrusion detection and prevention systems, and deep
packet inspection systems.

Key Features:

● Transparent Network Services: Enables seamless deployment of third-party network


appliances.
● Scalability: Automatically scales the network appliances with traffic.
● Simplified Management: Simplifies the deployment and management of inline network virtual
appliances.
Setting Up an Application Load Balancer
Step-by-Step Guide

1. Create an Application Load Balancer (ALB)


○ Open the EC2 Dashboard:
■ Log in to the AWS Management Console.
■ Navigate to the EC2 Dashboard.
○ Create a Load Balancer:
■ In the EC2 Dashboard, under "Load Balancing," click on "Load Balancers."
■ Click "Create Load Balancer" and select "Application Load Balancer."
○ Configure Basic Settings:
■ Name: Enter a name for your ALB (e.g., my-app-alb).
■ Scheme: Select "Internet-facing" if the ALB will handle public traffic or "Internal"
for private traffic.
■ IP address type: Choose between IPv4 or Dualstack (for both IPv4 and IPv6).
■ VPC: Select the Virtual Private Cloud (VPC) where your ALB will be deployed.
■ Availability Zones: Select at least two Availability Zones to ensure high
availability.
○ Configure Listeners and Security Groups:
■ Listeners: Add listeners for HTTP (port 80) and/or HTTPS (port 443).
■ Security Groups: Create or select a security group that allows inbound traffic on
the specified listener ports.
○ Configure Routing:
■ Target Groups: Create a new target group or select an existing one.
■ Name: Give your target group a name (e.g., my-target-group).
■ Target type: Choose the target type (Instances, IP addresses, or Lambda
functions).
■ Protocol: Set the protocol to HTTP or HTTPS.
■ Port: Set the port number to 80 (HTTP) or 443 (HTTPS).
■ VPC: Select the VPC.
○ Health Checks:
■ Configure health check settings to ensure that only healthy targets receive traffic.
■ Protocol: HTTP or HTTPS.
■ Path: Specify a health check path (e.g., /health).
■ Adjust other settings like health check interval, timeout, and thresholds as
needed.
○ Register Targets:
■ Add your EC2 instances or other targets to the target group.
■ You can manually register targets or let an Auto Scaling group manage this
dynamically.
○ Review and Create:
■ Review all your settings.
■ Click "Create" to launch your Application Load Balancer.

Monitoring and Management


● Monitoring: Use Amazon CloudWatch to monitor your load balancer’s performance and health.
Key metrics include request count, healthy host count, latency, and HTTP status codes.
● Logging: Enable access logs for your load balancer to capture detailed information about the
requests sent to your load balancer.
● Security: Ensure your security groups and IAM roles are configured to allow the necessary traffic
and access while maintaining security best practices.

Practical Example: Setting Up an Application Load Balancer with Auto


Scaling Groups
1. Create Target Groups:
○ Target Group 1: web-tier-target-group
■ Instances: web-instance-1, web-instance-2
○ Target Group 2: api-tier-target-group
■ Instances: api-instance-1, api-instance-2
2. ALB Listener Rules:
○ HTTP Listener on port 80
■ Default Rule: Forward to web-tier-target-group
■ Additional Rule: If path is /api/*, forward to api-tier-target-group
3. Create Auto Scaling Groups (ASGs):
○ web-tier-asg:
■ Launch Configuration: EC2 instances for the web service
■ Target Group: web-tier-target-group
■ Scaling Policy: Based on request count
○ api-tier-asg:
■ Launch Configuration: EC2 instances for the API service
■ Target Group: api-tier-target-group
■ Scaling Policy: Based on CPU utilization

Conclusion
Load balancing is a fundamental technique for building scalable, high-availability applications. AWS
provides multiple load balancer options to suit different needs, including the Application Load Balancer,
Network Load Balancer, Classic Load Balancer, and Gateway Load Balancer. Each type of load balancer
offers unique features and benefits, making it suitable for different types of workloads.
Using AWS Elastic Load Balancing with Auto Scaling groups ensures your application can handle varying
levels of traffic while maintaining high availability and performance. Proper configuration and monitoring of
these services are essential for maintaining a robust and scalable application infrastructure.

NOTE:
- It is target groups which basically connect the ALB with the ASG. Target groups can have even more
registered targets other than ASG introduced. ALB can have multiple target groups attached. By default
there will be round robin load balancing between the targets.

- A typical application under ALB should be stateless and should not have user generated files and / or
DB within the EC2

Auto scaling group does not directly attach to the load balancer. We actually specify target groups
associated with load balancer and that tgt group is populated with the instances which are created due to
the ASG policies of scaling in and scaling out.

You might also like