AWS User Data | How to run commands on startup Amazon Linux

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.

Step 1

First log into you AWS portal and then click services and EC2

Step 2

Next Click launch instance.

Step 3

Select Amazon Linux

Step 4

Leave the instance as mirco to get the free tier and click next Configure instance details

Step 5

Leave the defaults and scroll down to advanced details and expand it – enter the following lines into the textbox:

#!/bin/bash
yum install httpd -y
systemctl start httpd
systemctl stop firewalld
cd /var/www/html
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

Step 6

Leave the defaults and click next add tags

Step 7

Give your machine a name and click Next Configure Security Group.

Step 8

Allow port 80 from 0.0.0.0/0 on the security group and click review and launch

Step 9

Click Launch

Step 10

You can proceed without a keypair as we will not log into this instance

Step 11

click your instance ID

Step 12

Wait until your instance is running and then copy it’s pubic IP or dns name

Step 13

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:

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

1 Response to AWS User Data | How to run commands on startup Amazon Linux

  1. Pingback: AWS User Data | How to run commands on startup Amazon Linux – Linux directory

Leave a Reply

Your email address will not be published. Required fields are marked *