Introduction to AWS Compute & EC2 – A Beginner's Guide

If you're stepping into the world of cloud computing, understanding Amazon EC2 (Elastic Compute Cloud) is essential. Whether you're a developer, DevOps engineer, or just AWS-curious, this guide walks you through compute services in AWS with a real-world approach.

πŸ” What is Compute in the Cloud?

"Compute" refers to the processing power required to run applications, services, and workloads in the cloud. It includes resources like CPU, RAM, storage, and networking. AWS offers several compute options for different needs:

🧩 Types of Compute Services in AWS

  1. EC2 – Scalable virtual servers (most commonly used)

  2. Lambda – Serverless, event-driven compute

  3. ECS/EKS – Container orchestration using Docker/Kubernetes

  4. Lightsail – Simplified app hosting with GUI

  5. Elastic Beanstalk – Easy deployment over EC2

  6. Outposts – AWS hardware on-premises

  7. Batch – Efficient batch job execution

πŸ‘‰ Use Case Example:
Choose EC2 for hosting a Spring Boot application; Lambda for running a script when a file is uploaded to S3.


πŸ’‘ What is Amazon EC2?

Amazon EC2 offers scalable virtual servers in the AWS cloud. It gives you root access, the ability to configure networking, storage, and full OS-level control.

Key EC2 Concepts:

  • Instance – A virtual server

  • AMI (Amazon Machine Image) – A pre-configured OS + app software template

  • Instance Type – Hardware configuration (e.g., t2.micro)

  • Key Pair – Used for secure SSH access

  • Security Group – Virtual firewall to control access

  • Elastic IP – A static IP address


πŸ’Έ EC2 Pricing Models

  1. On-Demand – Pay per hour/second

  2. Reserved Instances – Commit 1–3 years for cost savings

  3. Spot Instances – Cheapest, but can be interrupted

  4. Free Tier – 750 hours/month for t2.micro/t3.micro for 12 months


πŸ” EC2 Best Practices

  • Use IAM roles instead of hardcoding credentials.

  • Tag resources for better management.

  • Restrict ports in Security Groupsβ€”only open what's needed.

  • Stop instances when not in use to avoid costs.


πŸ”§ Launching an EC2 Instance (Step-by-Step)

  1. Log in to AWS Console > EC2 > Launch Instance

  2. Select Amazon Linux 2 (Free Tier eligible)

  3. Choose t2.micro (or t3.micro)

  4. Add 8GB of storage

  5. Configure security group to allow:

    • SSH (port 22)

    • HTTP (port 80)

  6. Create and download your key pair (.pem file)

  7. Launch the instance!


🌐 Deploying a Web App to EC2

  1. Install Java & Git on the instance:

     sudo yum install git -y
     sudo yum install java-17-amazon-corretto -y
    
  2. Clone your GitHub repo:

     git clone https://github.com/yourname/spring-boot-app.git
     cd spring-boot-app
     java -jar demo-app.jar
    
  3. Or transfer your app JAR using SCP:

     scp -i your-key.pem app.jar ec2-user@<public-ip>:/home/ec2-user/
    
  4. Access the app in your browser via EC2’s public IP on port 8080 or 80.


πŸ“‚ Assignment: Deploy & Secure a WebApp

πŸ”§ Steps:

  1. Launch EC2, install Java, Git

  2. Upload Spring Boot app

  3. Open necessary ports via Security Groups

  4. Ensure app is reachable via REST endpoints

  5. Harden security – block unused ports

  6. Automatically shut down instance after a set time

πŸš€ Bonus:

  • Make the JAR file a service so it runs in the background

  • Upload/Read files to/from S3 via REST APIs


πŸ§ͺ DevOps Assignment: Automate it All!

Write a script that:

  • Provisions EC2

  • Installs dependencies

  • Clones and deploys the app

  • Opens required ports

  • Shuts down the instance after use

πŸ“Œ Make the script configurable for:

  • Instance type

  • Dependencies

  • Repo URL

0
Subscribe to my newsletter

Read articles from TechEazy Consulting directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

TechEazy Consulting
TechEazy Consulting