EC2 (Elastic compute Cloud)
Amazon EC2 is a fundamental AWS service for running virtual servers and applications in the cloud. Understanding AMI, instance types, key pairs, Security Groups, EBS, networking, instance creation, and lifecycle management provides a strong foundation for learning AWS and DevOps.
Amazon EC2 – Complete Guide
1. What is Amazon EC2?
Amazon EC2 (Elastic Compute Cloud) is an AWS service that provides virtual servers, called EC2 instances, in the cloud. It allows users to run websites, applications, APIs, databases, and other workloads without purchasing or maintaining physical servers.
EC2 provides flexibility because users can choose the required CPU, memory, storage, operating system, and networking configuration. Resources can also be scaled according to application requirements. AWS follows a pay-as-you-go pricing model.
2. Important EC2 Components
AMI
AMI (Amazon Machine Image) is a template used to create an EC2 instance. It contains the operating system and required configuration.
Examples include:
- Amazon Linux
- Ubuntu
- Windows Server
- Red Hat Enterprise Linux
Instance Type
An instance type defines the computing resources available to the instance, including CPU, memory, and network performance.
Examples:
t3.microt3.smallt3.mediumm7i.largec7i.large
Key Pair
A key pair provides secure authentication when connecting to an EC2 instance. Linux instances commonly use SSH with a private key.
Security Group
A Security Group acts as a virtual firewall and controls network traffic to and from an EC2 instance.
Common ports include:
- 22 – SSH
- 80 – HTTP
- 443 – HTTPS
- 3389 – RDP
EBS
Amazon EBS (Elastic Block Store) provides persistent block storage for EC2 instances. It can store operating system files, applications, databases, and logs.
3. EC2 Instance Types
AWS provides different instance families for different workloads.
General Purpose
Provides a balance of CPU, memory, and networking.
Examples:
t3, t4g, m7iUsed for: Web servers, APIs, development, and general applications.
Compute Optimized
Provides higher CPU performance.
Examples:
c7i, c7gUsed for: Batch processing and CPU-intensive applications.
Memory Optimized
Provides large amounts of memory.
Examples:
r7i, r7gUsed for: Large databases, analytics, and memory-intensive applications.
Storage Optimized
Designed for high storage and I/O performance.
Examples:
i7i, d3Used for: Data-intensive and storage-heavy workloads.
Accelerated Computing
Uses specialized hardware such as GPUs.
Examples:
p, gUsed for: Machine learning, AI, graphics, and video processing.
4. How to Create an EC2 Instance
Step 1: Open AWS Console
Log in to the AWS Management Console and open the EC2 service.
Step 2: Select Region
Choose the required AWS Region, such as Asia Pacific (Mumbai).
Step 3: Launch Instance
Select Instances → Launch instances.
Step 4: Enter Name
Give the instance a meaningful name, for example:
My-Web-ServerStep 5: Select AMI
Choose an operating system such as Ubuntu or Amazon Linux.
Step 6: Select Instance Type
Choose an instance type based on your workload and resource requirements.
Step 7: Select Key Pair
Create or select a key pair for secure access. Keep the private key safe.
Step 8: Configure Network
Select the VPC, subnet, public IP configuration, and Security Group. For a web server, ports 80 and 443 may be required, while SSH uses port 22.
Step 9: Configure Storage
Select the required EBS volume, for example a 20 GB gp3 volume.
Step 10: Launch
Review the configuration and click Launch Instance.
5. Connecting to Linux EC2
After the instance starts, use its public IP address to connect through SSH:
1
ssh -i my-key.pem ubuntu@<PUBLIC-IP>For Amazon Linux, the username is commonly
ec2-user.6. EC2 Lifecycle
The main EC2 states are:
- Pending – Instance is launching.
- Running – Instance is active.
- Stopping – Instance is shutting down.
- Stopped – Instance is powered off.
- Rebooting – Instance is restarting.
- Terminated – Instance has been permanently removed.
Stop means temporary shutdown, while Terminate means permanent removal.
7. EC2 Security Best Practices
- Use IAM roles instead of storing AWS credentials on instances.
- Restrict Security Group rules.
- Avoid unnecessarily exposing SSH to the internet.
- Keep the operating system updated.
- Use HTTPS for production applications.
- Store sensitive information securely.
- Monitor instances using CloudWatch.
- Back up important data.
Conclusion
Amazon EC2 is a fundamental AWS service for running virtual servers and applications in the cloud. Understanding AMI, instance types, key pairs, Security Groups, EBS, networking, instance creation, and lifecycle management provides a strong foundation for learning AWS and DevOps.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article