Create a new AWS EC2 instance, and set the User Script to the following:

This is handy for quick demos or testing — the instance comes up with Apache already running and serving a page that shows its hostname. I use this when I need to verify load balancer configurations or test auto-scaling groups, since each instance identifies itself in the response.

The user data script runs as root on first boot only. If you need Nginx instead of Apache, swap httpd for nginx. Make sure your security group allows inbound traffic on port 80, otherwise you won’t be able to reach the web server from outside the instance.

#!/bin/bash
sudo su
yum update -y
yum install -y httpd.x86_64
systemctl start httpd.service
systemctl enable httpd.service
echo "<h1>Serving from $(hostname -f)</h1>" > /var/www/html/index.html