DEV Community

Cover image for Beyond Static: Launching My First EC2 Instance with User Data
Eric Rodríguez
Eric Rodríguez

Posted on

Beyond Static: Launching My First EC2 Instance with User Data

Day 4 of going All-in on AWS.

Yesterday, I hosted a static site on S3. It was cool, but static. It had no brain. Today, I wanted compute power. I wanted a real computer in the cloud that I could control.

I decided to launch an Amazon EC2 (Elastic Compute Cloud) instance.

But I didn't want to just launch it and then manually install software like a beginner. I wanted to try a bit of "Infrastructure as Code" logic.

The Challenge: "User Data"

I learned that AWS allows you to pass a script to the instance that runs only once when it boots up. This is called User Data. Instead of SSH-ing in and typing yum install httpd manually, I told AWS to do it for me.

My Script:

Bash

!/bin/bash

yum update -y
yum install -y httpd
systemctl start httpd
echo "

Hello from my EC2 Server! This was automated.

" > /var/www/html/index.html
The Result

I clicked "Launch", waited 30 seconds for the status checks to pass, and pasted the Public IP into my browser.

It worked. I didn't touch the terminal. The server provisioned itself, installed Apache, and served my page automatically.

This is a small step, but it’s the difference between "managing servers" and "automating servers." Now I have a full Linux environment at my fingertips.

Top comments (0)