Introduction to Amazon EC2 and Creating an EC2 Instance in AWS
This article will help you learn about Amazon EC2 and how to create an Amazon EC2 Instance in AWS.
Published Dec 4, 2024
Amazon Elastic Compute Cloud (EC2) is a web service that provides secure, resizable compute capacity in the cloud. It's designed to make web-scale cloud computing easier for developers and businesses of all sizes.
Amazon Elastic Compute Cloud (Amazon EC2) offers the broadest and deepest compute platform, with over 750 instances and choice of the latest processor, storage, networking, operating system, and purchase model to help you best match the needs of your workload. We are the first major cloud provider that supports Intel, AMD, and Arm processors, the only cloud with on-demand EC2 Mac instances, and the only cloud with 400 Gbps Ethernet networking. We offer the best price performance for machine learning training, as well as the lowest cost per inference instances in the cloud. More SAP, high performance computing (HPC), ML, and Windows workloads run on AWS than any other cloud.
- Scale capacity up or down within minutes
- Automatic scaling with Auto Scaling groups
- Pay only for what you use
**2. Complete Control**
- Root/administrative access to instances
- Choose your operating system
- Configure security and networking
- Manage storage options
**3. Flexibility**
- Multiple instance types optimized for different use cases
- Choice of operating systems and software packages
- Various purchasing options (On-Demand, Reserved, Spot instances)
**4. Security**
- Virtual Private Cloud (VPC) for network isolation
- Security Groups for firewall configuration
- Integration with AWS IAM for access control
- Encryption options for data at rest and in transit
**5. Reliability**
- Multiple Availability Zones
- High availability options
- Automated backups and recovery
- Health monitoring and auto-recovery
## **Pricing Options:**
**1. On-Demand Instances**
- Pay by the hour or second
- No upfront costs or long-term commitments
- Best for short-term, irregular workloads
**2. Reserved Instances (RI)**
- Up to 72% discount compared to On-Demand
- 1 or 3-year term commitment
- Payment options: No upfront, Partial upfront, All upfront
**3. Spot Instances**
- Up to 90% off On-Demand prices
- Ideal for flexible start and end times
- Good for batch processing, scientific research
**4. Dedicated Hosts**
- Physical servers dedicated to your use
- Can help address compliance requirements
- Allows you to use existing server-bound software licenses
## Here's a detailed guide to create an EC2 instance with associated networking components in AWS:
### Create a VPC (Virtual Private Cloud):
1. Navigate to VPC Dashboard in AWS Console
2. Click "Create VPC" named my-vpc-01 .
3. Specify CIDR block (e.g., 10.0.0.0/16)
4. Enable DNS hostnames and DNS support
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpg2ygp3cw0egq34ulp8.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czgdaf19kn5a0xjd6mnq.png)
### Create Subnets:
1. Create at least two subnets (public and private) in different availability zones
2. For public subnet: e.g., 10.0.1.0/24
3. For private subnet: e.g., 10.0.2.0/24
4. Enable "Auto-assign public IPv4 address" for public subnet
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l1qy4evyqltf84gufbxg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhxulejcktgq5iaf93jz.png)
### Create Internet Gateway (IGW):
1. Create a new Internet Gateway
2. Attach it to your VPC
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k68082fcdr5vzn3nub06.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hl0g9gysi792jrzphv7.png)
### Create Route Tables:
1. Create a public route table
2. Add route to Internet Gateway (0.0.0.0/0 → IGW)
3. Associate public subnet with this route table
4. Create a private route table for private subnet
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/68gd3ji9bpwfk3ao21yr.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u8bqd3sevopdpxi32xrg.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5cq91dqnjw9ian5vp6q.png)
### Configure Security Group:
1. Create a new security group in your VPC
2. Add inbound rules for required ports:
- SSH (Port 22) from your IP
- HTTP (Port 80) if needed
- HTTPS (Port 443) if needed
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmxdckl7dy31ldwwnwz3.png)
### Launch EC2 Instance:
1. Click "Launch Instance" in EC2 Dashboard
2. Choose an Amazon Machine Image (AMI)
3. Select instance type (e.g., t2.micro)
4. Configure network settings:
5. Select your VPC
6. Choose public subnet if you need internet access
7. Enable auto-assign public IP
8. Select the security group you created
9. Add storage as needed
10. Create or select a key pair for SSH access
11. Review and launch
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jd2xoh18ud9rpjt2w91r.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlwzypyp30diotqw8xkq.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ptctkdsxotedn38zvkh4.png)
**Hurray! myinstance-01 is successfully created and running on AWS Cloud.**
## Best Practices:
- Right-sizing: Choose appropriate instance types
- Use Auto Scaling for optimal resource utilization
- Implement proper security measures
- Regular backup and disaster recovery planning
- Monitor and optimize costs using AWS Cost Explorer
## Conclusion
Amazon EC2 stands as a foundational pillar in AWS's cloud computing infrastructure, offering a comprehensive solution for businesses of all sizes. Through its flexible computing resources, diverse pricing models (including On-Demand, Reserved, and Spot instances), and robust security features, EC2 enables organizations to significantly reduce their IT infrastructure costs while maintaining high availability and scalability. The service's seamless integration with the AWS ecosystem, coupled with features like Auto Scaling, load balancing, and detailed monitoring through CloudWatch, allows businesses to focus on their core operations rather than infrastructure management. Whether deploying a simple web application or running complex enterprise workloads, EC2's ability to provide secure, resizable compute capacity, combined with its pay-as-you-go pricing model and extensive management tools, makes it an invaluable resource for modern cloud computing needs. By following best practices such as right-sizing instances, implementing proper security measures, and maintaining regular backups, organizations can leverage EC2 to achieve optimal performance, cost-effectiveness, and reliability in their cloud infrastructure.