While you launch an EC2 occasion, you should use the user-data
to bootstrap a occasion creation script.
We are able to 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>Whats up 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 cases
.
Choose an Amazon Machine Picture (AMI). We are going to choose Amazon Linux 2
.
Select an occasion kind from the checklist. We are going to 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 Consumer 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>Whats up 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 Kind
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 preserve 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 high.
Within the beneath 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 deal with
and open a brand new browser tab/window and paste it within the deal with bar.

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