Introduction

Amazon EC2 (Elastic Compute Cloud) provides scalable computing capacity in the AWS cloud. In this hands-on guide, we'll walk through launching and configuring an EC2 instance from scratch.

Prerequisites

  • AWS Account (Free Tier eligible)
  • Basic understanding of Linux
  • SSH client installed
  • Step 1: Choose an AMI

    Log into the AWS Console and navigate to EC2:

    1. Click Launch Instance

    2. Select Amazon Linux 2023 AMI (Free Tier eligible)

    3. Choose instance type: t2.micro (Free Tier)

    Step 2: Configure Security Group

    Create a security group with these rules:

    Inbound Rules:
    
  • SSH (Port 22) - Your IP only
  • HTTP (Port 80) - Anywhere (0.0.0.0/0)
  • HTTPS (Port 443) - Anywhere (0.0.0.0/0)
  • Step 3: Create Key Pair

    # Download the .pem file and set permissions
    

    chmod 400 my-key-pair.pem

    # Connect via SSH

    ssh -i my-key-pair.pem ec2-user@<public-ip>

    Step 4: Initial Server Setup

    # Update system
    

    sudo yum update -y

    # Install essential packages

    sudo yum install -y nginx git

    # Start Nginx

    sudo systemctl start nginx

    sudo systemctl enable nginx

    # Verify

    curl http://localhost

    Step 5: Attach Elastic IP

    1. Navigate to Elastic IPs in EC2 console

    2. Click Allocate Elastic IP address

    3. Select the IP → ActionsAssociate Elastic IP address

    4. Select your instance

    Security Best Practices

  • Use IAM roles instead of access keys
  • Enable CloudWatch monitoring
  • Set up automated backups with AMI snapshots
  • Use Systems Manager Session Manager instead of SSH
  • Enable VPC Flow Logs
  • Cost Optimization Tips

  • Use Reserved Instances for steady workloads
  • Use Spot Instances for fault-tolerant workloads
  • Right-size your instances using CloudWatch metrics
  • Set up billing alerts

Conclusion

You now have a running EC2 instance with proper security configuration. Next steps: deploy your application and set up a load balancer.