EC2 : Amazon Elastic Compute Cloud

EC2 : Amazon Elastic Compute Cloud

Amazon Elastic Compute Cloud (EC2) is a core service in AWS that provides scalable compute capacity in the cloud. EC2 allows users to run virtual machines, called instances, with different configurations based on specific use cases. This article explores EC2 instance types, pricing, CPU credits, storage, key pairs, Elastic IP addresses, user data scripts, and purchasing options.

EC2 Instance Types

EC2 instances are categorized into different types based on their hardware and intended workloads. These categories include:

  • General Purpose (e.g., t3, m5, m6i) - Balanced compute, memory, and networking for a variety of applications.
  • Compute Optimized (e.g., c6i, c5) - High-performance processors for compute-heavy tasks.
  • Memory Optimized (e.g., r6i, x2idn) - High memory instances for database and caching applications.
  • Storage Optimized (e.g., i3, i4i, d3) - Designed for high IOPS and data-intensive applications.
  • Accelerated Computing (e.g., p4, inf1, g5) - GPU-based instances for AI, ML, and graphic processing.

Example Costs

EC2 instance pricing varies by instance type and region. Here are example costs (on-demand, US East region):

  • t3.micro (1 vCPU, 1GB RAM) - $0.0104/hour
  • m5.large (2 vCPUs, 8GB RAM) - $0.096/hour
  • c5.2xlarge (8 vCPUs, 16GB RAM) - $0.34/hour

Choosing the Right Instance Type

  • Use t-series burstable for low CPU workloads.
  • Opt for m-series for general applications.
  • Choose c-series for high compute needs.
  • Select r/x-series for database-heavy applications.
  • Prefer GPU-based instances for AI/ML workloads.

Understanding CPU Credits

EC2 t-series instances operate on a CPU credit system, allowing them to burst beyond baseline performance for short periods. Each instance earns CPU credits per hour and consumes them when utilizing high CPU usage.

Example: CPU Credit Calculation

  • A t3.micro instance earns 6 CPU credits per hour.
  • Each vCPU credit allows 100% usage for 1 minute.
  • If an instance bursts to 100% for 5 minutes, it will consume 5 credits.
  • Running out of credits causes throttling to baseline performance.

Cost Calculation

If the t3.micro instance exceeds its credit allocation, additional CPU usage incurs an extra charge of $0.05 per vCPU-hour.

EC2 Storage and Volumes

Elastic Block Store (EBS)

Amazon EBS provides block storage for EC2 instances, offering high performance and persistence.

Why Use EBS?

  • Persistent storage, unlike instance store which is temporary.
  • High availability and durability.
  • Can be resized and attached to different instances.

Example Use Case

A database application requires persistent storage even if the instance is terminated. EBS ensures data is retained across reboots.

Managing EC2 Key Pairs

Key pairs allow secure SSH access to EC2 instances. AWS provides:

  • Public Key: Stored on AWS and associated with the instance.
  • Private Key: Downloaded and used for authentication.

Best Practices

  • Store private keys securely.
  • Use different key pairs for different environments (e.g., dev, prod).
  • Rotate keys regularly for security.

Deep Dive into Elastic IP Addresses

An Elastic IP (EIP) is a static, public IPv4 address that users can assign to EC2 instances.

Example Scenario

A web server needs a stable public IP for external access. Attaching an EIP ensures the IP does not change even if the instance is stopped and restarted.

User Data Scripts

AWS EC2 allows users to execute scripts upon instance launch using User Data.

How It Works

  • Scripts run on first boot as root.
  • Common use cases include software installation, instance configuration, and automation.

Example Use Case

A web server instance can be configured with:

#!/bin/bash
yum update -y
yum install httpd -y
systemctl enable httpd
systemctl start httpd
echo "Welcome to EC2" > /var/www/html/index.html        

This script installs and starts Apache on launch.

EC2 Purchasing Options

AWS offers multiple purchasing options to balance cost and flexibility.


Choosing the Right Plan

  • Use On-Demand for unpredictable workloads.
  • Choose Reserved Instances for long-term steady applications.
  • Opt for Spot Instances for batch processing and flexible workloads.
  • Select Dedicated Hosts for compliance-driven workloads.

By understanding EC2 instances, pricing, CPU credits, storage, key pairs, Elastic IPs, and user data scripts, businesses can optimize cloud computing for performance and cost-effectiveness.

要查看或添加评论,请登录

Deepak Mandal的更多文章

  • AWS VPC (Virtual Private Cloud) and Its Key Components

    AWS VPC (Virtual Private Cloud) and Its Key Components

    1. What is an IP Address? An IP (Internet Protocol) address is a numerical label assigned to each device connected to a…

  • AWS IAM: How to manage Users

    AWS IAM: How to manage Users

    AWS Identity and Access Management (IAM) is a critical component of securing your AWS environment. In this guide, we…

  • Onboarding AWS

    Onboarding AWS

    Amazon Web Services (AWS) is a leading cloud platform that offers a broad range of services and tools for developers…

  • Understanding Amazon Web Services (AWS) Cloud Computing

    Understanding Amazon Web Services (AWS) Cloud Computing

    Introduction In today’s rapidly evolving digital landscape, businesses are increasingly turning to cloud computing to…

    5 条评论
  • Case Study: Typo.so

    Case Study: Typo.so

    Role: Senior Developer and DevOps Lead Overview Typo.so is a dynamic and feature-rich content creation platform…

  • The Role of Algorithms in Computing

    The Role of Algorithms in Computing

    Introduction Algorithms are the foundation of computing. They are step-by-step computational procedures that transform…

  • Implementing Microservice Communication (Part 2)

    Implementing Microservice Communication (Part 2)

    We have done our first part where we did get understanding of Communication style we can implement in between services.…

  • Implementing Microservice Communication (Part 1)

    Implementing Microservice Communication (Part 1)

    Finding the optimal technology for facilitating communication between microservices entails careful consideration of…

  • Communication styles in microservices

    Communication styles in microservices

    To even start thinking about any implementation, we always need something we called communication style. Defining…

  • Controllers in NestJS

    Controllers in NestJS

    Controllers play a crucial role in any web application, as they act as the intermediary between the client’s requests…

    1 条评论

社区洞察

其他会员也浏览了