AWS EC2 (Elastic Compute Cloud)

What is EC2?

AWS EC2 (Elastic Compute Cloud) is a service that provides resizable virtual servers in the cloud. It allows users to run applications without needing physical hardware.

With EC2, you can easily scale your compute capacity up or down based on demand.

Why Use EC2?

  • Scalability: Launch or terminate instances as needed.
  • Cost-Effective: Pay only for the compute power you use.
  • Flexibility: Choose from different instance types and operating systems.
  • Security: Secure your instances using IAM roles, security groups, and key pairs.
  • Integration: Works with other AWS services like S3, RDS, and Load Balancers.

EC2 Pricing Models

Pricing Model Description
On-Demand Pay as you go. Best for short-term workloads.
Reserved Instances Commit for 1-3 years to get a lower price.
Spot Instances Bid for unused capacity at a lower cost.
Dedicated Hosts Physical servers dedicated to your organization.

Launching an EC2 Instance

Follow these steps to launch an EC2 instance:

  1. Go to the AWS EC2 console.
  2. Click Launch Instance.
  3. Select an Amazon Machine Image (AMI).
  4. Choose an Instance Type (e.g., t2.micro for free tier).
  5. Configure instance details, add storage, and set security groups.
  6. Launch and connect using SSH.

Connecting to an EC2 Instance

Use SSH to connect to your EC2 instance from your terminal:

ssh -i your-key.pem ec2-user@your-ec2-public-ip

Make sure your security group allows inbound SSH connections (port 22).

Stopping and Terminating EC2 Instances

You can stop or terminate an EC2 instance based on your needs:

  • Stopping an instance: Preserves your data but stops billing for compute.
  • Terminating an instance: Deletes the instance and all associated data.

Conclusion

EC2 is a fundamental AWS service for running cloud applications. It offers flexible pricing, security, and scalability.

Next Topic: AWS S3 (Simple Storage Service)

In the next post, we will explore AWS S3, a powerful cloud storage service for storing and retrieving data efficiently.