If you launch an EC2 occasion, you need to use the user-data
to bootstrap a occasion creation script.
We will use the next code to begin an internet server and echo out it’s occasion id:
#!/bin/bash
yum replace -y
yum set up -y httpd
systemctl begin httpd
systemctl allow httpd
echo "<h1>Howdy World from $(hostname -f)</h1>" > /var/www/html/index.html
Code language: Bash (bash)
Steps to create a brand new bootstrapped occasion
Step 1 – Launch a brand new occasion
Login to your EC2 console and click on Launch situations
.
Choose an Amazon Machine Picture (AMI). We are going to choose Amazon Linux 2
.
Select an occasion sort from the checklist. We are going to use a Free Tier Eligible t2.micro
. Click on Subsequent.
Hold all of the choices as default and scroll to the underside of the web page. Within the Person Information
textfield, enter the next code snippet:
#!/bin/bash
yum replace -y
yum set up -y httpd
systemctl begin httpd
systemctl allow httpd
echo "<h1>Howdy World from $(hostname -f)</h1>" > /var/www/html/index.html
Code language: Bash (bash)

Click on Subsequent.
Don’t change any Storage choices, and click on Subsequent.
Step 2 – Add tags
Click on Add Tag
and enter a Key of Title
and a worth of Bootstrapped Net Server

Click on Subsequent.
Step 3 – Create a safety group
Choose Create a brand new safety group
and provides it a reputation and outline of EC2 default
and Default safety group entry for EC2
respectively.
Click on Add Rule
and alter the Sort
to HTTP
.
Click on Evaluate and Launch.

Click on Launch.
Step 4 – Create and obtain a key pair
Create a brand new key pair
from the primary dropdown and provides it a reputation of EC2 Occasion
.
Click on Obtain Key Pair
and maintain it protected. As that is the one time you’ll ever be capable to obtain it.

As soon as downloaded, click on Launch Situations
.
Step 5 – View the occasion
On the Standing Web page, click on on the occasion id that’s proven on the high.
Within the under instance, the occasion id is i-062bd33e3189adfcc
.

After a couple of seconds, you will note the brand new occasion up and working.

Copy the Public IPv4 deal with
and open a brand new browser tab/window and paste it within the deal with bar.

The occasion is now up and working and serving HTTP visitors on port 80.