EC2 : Amazon Elastic Compute Cloud
Deepak Mandal
Senior Software Engineer Talks about #typescript #nextjs #nestjs #microservices #scalablesystem
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:
Example Costs
EC2 instance pricing varies by instance type and region. Here are example costs (on-demand, US East region):
Choosing the Right Instance Type
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
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?
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:
Best Practices
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
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
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.