100 Days of AWS – Day 13: Mini-Project - Launch a Web Server on EC2
Welcome to Day 13! It's time to get our hands dirty. After a week of learning the theory behind EC2, we're going to build something tangible: a live, public-facing web server. This is a "Hello, World!" project for cloud infrastructure and a rite of passage for every cloud engineer.
Goal: To launch an EC2 instance that automatically installs and runs an Apache web server, accessible from the internet.
Step-by-Step Guide
Step 1: Navigate to the EC2 Dashboard & Launch Instance
In the AWS Management Console, go to the EC2 service and click on "Launch instances".
Step 2: Choose an AMI and Instance Type
- AMI: Select the Amazon Linux 2 AMI. It's common, reliable, and free-tier eligible.
- Instance Type: Choose the t2.micro, as it is also part of the AWS Free Tier.
Step 3: Configure the User Data Script
This is the most important step for automation. Scroll down to the "Advanced Details" section and find the User Data field. Copy and paste the following script into the text box.
This script will run automatically the first time the instance starts.
#!/bin/bashyum update -y yum install -y httpd.x86_64 systemctl start httpd.service systemctl enable httpd.service#!/bin/bash: Specifies that this is a bash script.yum update -y: Updates all system packages.yum install -y httpd.x86_64: Installs the Apache web server (httpd).systemctl start httpd.service: Starts the Apache service.systemctl enable httpd.service: Configures the service to start automatically on boot.
Step 4: Configure the Security Group
This is the firewall for your instance. On the "Configure Security Group" page:
- Select "Create a new security group".
- By default, it will have an SSH rule (Port 22). Leave that rule.
- Click "Add Rule".
- For Type, select HTTP.
- The Port Range will automatically set to 80.
- For Source, select Anywhere (
0.0.0.0/0). This allows anyone on the internet to access your web page.
Step 5: Launch and Verify
Review your settings and click "Launch". You will be prompted to select or create a key pair. You'll need this to SSH into your instance, so create one and download it safely.
Once your instance is in the "Running" state, select it and find its Public IPv4 address in the details panel. Copy this IP address.
Paste the IP address into your web browser's address bar. You should see the Apache test page!
Congratulations! You have successfully launched a web server on AWS!
Troubleshooting
Web page doesn't load? The most common reason is the Security Group. Double-check that you have a rule allowing HTTP traffic on port 80 from the source
0.0.0.0/0.
0 Comments