Userdata on AWS allows you to run commands on start-up when you launch an EC2 instance on AWS. This is known as boot strapping your instance. In this example we will be boot strapping Amazon Linux with the Apache web server.
First log into you AWS portal and then click services and EC2
Next Click launch instance.
Select Amazon Linux
Leave the instance as mirco to get the free tier and click next Configure instance details
Leave the defaults and scroll down to advanced details and expand it – enter the following lines into the textbox:
yum install httpd -y
systemctl start httpd
systemctl stop firewalld
echo "this is my test site" > index.html
The text in the code block above installs apache and adds an simple webpage that reads this is my test site. Finally click Next add storage
Leave the defaults and click next add tags
Give your machine a name and click Next Configure Security Group.
Allow port 80 from 0.0.0.0/0 on the security group and click review and launch
You can proceed without a keypair as we will not log into this instance
click your instance ID
Wait until your instance is running and then copy it’s pubic IP or dns name
Open a new browser and enter the pubic IP of your Linux instance into the address bar. You should now see the simple webpage we created.
A full video tutorial can be found here: