Namaste, future Full-Stack Developers! Welcome to a foundational lesson in cloud computing. Today, we’re unlocking the power of Amazon Elastic Compute Cloud (EC2) – the heart of AWS’s compute services. Imagine needing a powerful computer to run your applications, but without the hassle of buying, maintaining, or upgrading hardware. That’s exactly what EC2 offers: virtual servers in the cloud, ready to scale with your ambitions.
In this lesson, you’ll learn what EC2 is, why it’s indispensable for modern applications, and most importantly, how to launch and connect to your very own virtual server, setting the stage for deploying your full-stack projects.
Amazon EC2 provides resizable compute capacity in the cloud. Think of it as renting a virtual computer (called an instance) from Amazon Web Services. You get to choose its operating system, processing power, memory, and storage, just like you would with a physical machine. The magic? You only pay for what you use, and you can scale up or down in minutes.
For full-stack developers, EC2 is your canvas in the cloud. It’s where your backend APIs run, your databases connect, and your frontend assets are served. It allows you to:
Before we launch our first instance, let’s understand some core terminology:
An EC2 Instance is simply a virtual server. AWS offers a wide variety of instance types, each optimized for different workloads:
t2.micro, t3.large). Great for web servers and development environments.c5.xlarge). Ideal for compute-intensive applications.r5.xlarge). Perfect for databases and in-memory caches.i3.xlarge). For data warehousing and NoSQL databases.You’ll also choose an Amazon Machine Image (AMI), which is a template containing the operating system (e.g., Amazon Linux, Ubuntu, Windows Server), application server, and any pre-installed software packages.
EC2 offers flexible pricing to suit various needs:
Auto Scaling automatically adjusts the number of EC2 instances in your application based on demand. If traffic increases, it launches more instances; if traffic decreases, it terminates them, ensuring optimal performance and cost efficiency.
Security Groups act as virtual firewalls for your instances, controlling inbound and outbound traffic. You define rules (e.g., allow SSH on port 22 from your IP, allow HTTP on port 80 from anywhere). Instances run within a Virtual Private Cloud (VPC), which is your isolated network environment in AWS.
Amazon Elastic Block Store (EBS) provides persistent block storage volumes for use with EC2 instances. Think of them as network-attached hard drives that remain even if your instance is terminated.
Let’s get practical! We’ll launch a basic t2.micro (Free Tier eligible) instance running Amazon Linux 2, and then connect to it.
Go to console.aws.amazon.com and sign in with your AWS account.
In the AWS Console search bar, type “EC2” and select the EC2 service. This will take you to the EC2 Dashboard.
On the EC2 Dashboard, click the orange “Launch instance” button.
You’ll see a list of AMIs. Select the “Amazon Linux 2 AMI (HVM) – Kernel 5.10, SSD Volume Type”. Make sure it’s marked “Free tier eligible”. This is a robust and widely used Linux distribution.
Select “t2.micro”. This instance type is also “Free tier eligible” and suitable for learning and small applications.
Click “Next: Configure Instance Details”.
For now, you can leave most settings as default. Ensure “Auto-assign Public IP” is set to “Enable” so your instance gets a public IP address for internet access.
Click “Next: Add Storage”.
The default 8 GiB General Purpose SSD (gp2) volume is usually sufficient for a basic instance and falls within the Free Tier. You can increase it if needed (up to 30 GiB for Free Tier).
Click “Next: Add Tags”. (Optional: Add a tag like Key: Name, Value: MyWebServer)
Click “Next: Configure Security Group”.
This is crucial for security! A Security Group acts as a virtual firewall. We need to allow SSH access to connect to our instance. You have two options:
web-server-sg) and a description.0.0.0.0/0) for broader access (less secure).Click “Review and Launch”.
Review all your settings. When you’re ready, click “Launch”.
A pop-up will appear asking you to select an existing key pair or create a new one. A key pair (.pem file) is essential for securely connecting to your instance via SSH.
my-ec2-key)..pem file securely! You cannot download it again.You’ll see a confirmation page. Click “View Instances” to go back to the EC2 Dashboard and see your instance launching.
Once your instance’s “Instance state” changes to “running” (it might take a minute or two), you can connect to it.
On the EC2 Dashboard, select your running instance. In the “Details” tab below, find the “Public IPv4 address” or “Public IPv4 DNS”. Copy one of them.
Open your terminal (macOS/Linux) or use Git Bash (Windows). Navigate to the directory where you saved your .pem file.
Change the permissions of your key file to be read-only by the owner:
chmod 400 my-ec2-key.pem
Use the ssh command. Replace my-ec2-key.pem with your key file name and your-public-ip with your instance’s public IP address. For Amazon Linux 2, the default username is ec2-user.
ssh -i "my-ec2-key.pem" ec2-user@your-public-ip
If it’s your first time connecting, you might be asked to confirm the authenticity of the host. Type yes and press Enter.
Congratulations! You are now logged into your virtual server in the cloud!
Now that you’ve launched and connected to your EC2 instance, let’s make it serve a simple web page!
sudo yum update -y
sudo amazon-linux-extras install nginx1 -y
sudo systemctl start nginx
sudo systemctl enable nginx
0.0.0.0/0).You’ve just taken a massive step in your cloud journey! You now understand what Amazon EC2 is, its key components, and how to provision a virtual server. More importantly, you’ve gained hands-on experience by launching an instance, connecting to it, and even deploying a basic web server. This fundamental skill is the bedrock for deploying almost any application in the AWS cloud.
Keep practicing, and soon you’ll be confidently managing your cloud infrastructure!