DEV Community

Elone.rajeev
Elone.rajeev

Posted on

πŸš€ Learn AWS EC2: Ultimate Beginner's Guide 🌐

Welcome to the AWS EC2 Tutorial! This guide will take you through everything you need to know about Amazon Elastic Compute Cloud (EC2)β€”from launching instances to hosting your first webpage!


🎯 What is AWS EC2?

Amazon EC2 is a web service that provides resizable compute capacity in the cloud. It enables businesses to deploy applications quickly without hardware investments.


πŸ“‹ Table of Contents

  1. 🌟 Why Learn EC2?
  2. πŸš€ Getting Started
  3. πŸ“¦ EC2 Instance Types
  4. βš™οΈ Launching an EC2 Instance
  5. 🌐 Hosting a Simple Webpage
  6. πŸ”’ Security Best Practices
  7. πŸ“ˆ Monitoring and Scaling
  8. πŸŽ‰ Conclusion

🌟 Why Learn EC2?

  • πŸš€ Cloud Computing Mastery: EC2 is the backbone of AWS services.
  • πŸ’Ό Career Growth: EC2 knowledge is crucial for DevOps, cloud engineers, and developers.
  • 🌍 Real-World Applications: Use EC2 to host websites, deploy applications, or run data pipelines.

πŸš€ Getting Started

Prerequisites

Before you begin, ensure you have:

  • βœ… An AWS account (free-tier eligible).
  • βœ… Basic knowledge of cloud computing.

πŸ“¦ EC2 Instance Types

AWS EC2 offers various instance types tailored for different workloads:

Type Use Case Examples
General Balanced performance t2.micro, t3.small
Compute High-performance computing c5.large, c6i.xlarge
Memory Memory-intensive apps r5.large, r6g.xlarge
Storage Data-heavy workloads i3.large, i4i.xlarge
GPU Machine learning, gaming g5.large, p3.2xlarge

βš™οΈ Launching an EC2 Instance

Follow these steps to launch your first EC2 instance:

  1. Login to AWS Console πŸ–₯️

    • Navigate to EC2 under the "Compute" section.
  2. Click "Launch Instance" πŸš€

    • Provide a name for your instance.
    • Select an AMI (Amazon Machine Image) like Ubuntu, Amazon Linux, or Windows Server.
  3. Choose an Instance Type πŸ–±οΈ

    • For beginners, choose t2.micro (free-tier eligible).
  4. Configure Security Groups πŸ”’

    • Add rules to allow inbound traffic for HTTP (port 80) and SSH (port 22).
  5. Key Pair πŸ—οΈ

    • Create or select an existing key pair for secure access.
  6. Launch Your Instance πŸŽ‰

    • Click Launch Instance and wait for it to initialize.

🌐 Hosting a Simple Webpage

Here’s how you can host a basic index.html file on your EC2 instance.

Step 1: Install a Web Server

Log into your EC2 instance via SSH and run the following commands to install a web server:

# Update the package manager
sudo apt update  

# Install Apache2
sudo apt install apache2 -y  

# Start Apache2 service
sudo systemctl start apache2  

# Enable Apache2 to start on boot
sudo systemctl enable apache2  
Enter fullscreen mode Exit fullscreen mode

Step 2: Create Your Webpage

Navigate to the default web server directory and create an index.html file:

# Navigate to the default directory
cd /var/www/html  

# Create or edit the index.html file
sudo nano index.html  
Enter fullscreen mode Exit fullscreen mode

Add the following content to your index.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to My Webpage</title>
</head>
<body>
    <h1>πŸš€ Welcome to My First AWS EC2 Hosted Webpage!</h1>
    <p>This is a simple webpage hosted on an EC2 instance.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save and exit (Ctrl+O, Enter, Ctrl+X).

Step 3: Open Your Webpage

  • In your browser, navigate to: http://<Public_IP_of_EC2_Instance>

You should see your index.html webpage live! πŸŽ‰


πŸ”’ Security Best Practices

  1. Use Security Groups: Restrict inbound traffic to only required ports.
  2. Key Management: Keep your .pem file secure.
  3. IAM Roles: Assign least privilege roles to your instances.

πŸŽ‰ Conclusion

With this guide, you’ve:

  • Launched your first EC2 instance.
  • Installed a web server.
  • Hosted your first index.html webpage.

Continue exploring AWS to enhance your cloud computing skills!

Need Help? Reach out on AWS Forums or join the AWS Community.


Happy Hosting! πŸš€



By Rajeev Kumar
Enter fullscreen mode Exit fullscreen mode

Top comments (0)