If you launch an EC2 occasion, you should use the user-data
to bootstrap a occasion creation script.
We will use the next code to start out an online 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>Good day 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’ll choose Amazon Linux 2
.
Select an occasion sort from the listing. We’ll use a Free Tier Eligible t2.micro
. Click on Subsequent.
Preserve all of the choices as default and scroll to the underside of the web page. Within the Person Knowledge
textfield, enter the next code snippet:
#!/bin/bash
yum replace -y
yum set up -y httpd
systemctl begin httpd
systemctl allow httpd
echo "<h1>Good day 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 Identify
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 secure. As that is the one time you’ll ever have the ability to obtain it.

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

After just a few seconds, you will notice the brand new occasion up and operating.

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

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