Once you launch an EC2 occasion, you should utilize 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
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 kind from the record. We’ll 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 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>Good day World from $(hostname -f)</h1>" > /var/www/html/index.html
```<determine class="wp-block-image size-large">
<img decoding="async" loading="lazy" width="683" top="350" src="https://ao.ms/wp-content/uploads/2022/03/1-683x350.png" alt="" class="wp-image-8763" srcset="https://ao.ms/wp-content/uploads/2022/03/1-683x350.png 683w, https://ao.ms/wp-content/uploads/2022/03/1-300x154.png 300w, https://ao.ms/wp-content/uploads/2022/03/1-768x394.png 768w, https://ao.ms/wp-content/uploads/2022/03/1-1536x787.png 1536w, https://ao.ms/wp-content/uploads/2022/03/1.png 1920w" sizes="(max-width: 683px) 100vw, 683px" /> </determine>
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 Internet Server`<determine class="wp-block-image size-large">
<img decoding="async" loading="lazy" width="800" top="254" src="https://ao.ms/wp-content/uploads/2022/03/image-800x254.png" alt="" class="wp-image-8770" srcset="https://ao.ms/wp-content/uploads/2022/03/image-800x254.png 800w, https://ao.ms/wp-content/uploads/2022/03/image-300x95.png 300w, https://ao.ms/wp-content/uploads/2022/03/image-768x243.png 768w, https://ao.ms/wp-content/uploads/2022/03/image-1536x487.png 1536w, https://ao.ms/wp-content/uploads/2022/03/image-2048x649.png 2048w" sizes="(max-width: 800px) 100vw, 800px" /> </determine>
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 Evaluation and Launch.<determine class="wp-block-image size-large">
<img decoding="async" loading="lazy" width="701" top="350" src="https://ao.ms/wp-content/uploads/2022/03/2-701x350.png" alt="" class="wp-image-8764" srcset="https://ao.ms/wp-content/uploads/2022/03/2-701x350.png 701w, https://ao.ms/wp-content/uploads/2022/03/2-300x150.png 300w, https://ao.ms/wp-content/uploads/2022/03/2-768x384.png 768w, https://ao.ms/wp-content/uploads/2022/03/2-1536x767.png 1536w, https://ao.ms/wp-content/uploads/2022/03/2.png 1920w" sizes="(max-width: 701px) 100vw, 701px" /> </determine>
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 protected. As that is the one time you'll ever be capable to obtain it.<determine class="wp-block-image size-large is-resized">
<img decoding="async" loading="lazy" src="https://ao.ms/wp-content/uploads/2022/03/3-470x350.png" alt="" class="wp-image-8765" width="622" top="463" srcset="https://ao.ms/wp-content/uploads/2022/03/3-470x350.png 470w, https://ao.ms/wp-content/uploads/2022/03/3-300x223.png 300w, https://ao.ms/wp-content/uploads/2022/03/3-768x572.png 768w, https://ao.ms/wp-content/uploads/2022/03/3-1536x1144.png 1536w, https://ao.ms/wp-content/uploads/2022/03/3.png 1722w" sizes="(max-width: 622px) 100vw, 622px" /> </determine>
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 beneath instance, the occasion id is `i-062bd33e3189adfcc`.<determine class="wp-block-image size-large is-resized">
<img decoding="async" loading="lazy" src="https://ao.ms/wp-content/uploads/2022/03/4-505x350.png" alt="" class="wp-image-8766" width="704" top="488" srcset="https://ao.ms/wp-content/uploads/2022/03/4-505x350.png 505w, https://ao.ms/wp-content/uploads/2022/03/4-300x208.png 300w, https://ao.ms/wp-content/uploads/2022/03/4-768x533.png 768w, https://ao.ms/wp-content/uploads/2022/03/4-1536x1066.png 1536w, https://ao.ms/wp-content/uploads/2022/03/4.png 1920w" sizes="(max-width: 704px) 100vw, 704px" /> </determine>
After a number of seconds, you will notice the brand new occasion up and working.<determine class="wp-block-image size-large is-resized">
<img decoding="async" loading="lazy" src="https://ao.ms/wp-content/uploads/2022/03/5-508x350.png" alt="" class="wp-image-8767" width="704" top="485" srcset="https://ao.ms/wp-content/uploads/2022/03/5-508x350.png 508w, https://ao.ms/wp-content/uploads/2022/03/5-300x207.png 300w, https://ao.ms/wp-content/uploads/2022/03/5-768x530.png 768w, https://ao.ms/wp-content/uploads/2022/03/5-1536x1059.png 1536w, https://ao.ms/wp-content/uploads/2022/03/5.png 1920w" sizes="(max-width: 704px) 100vw, 704px" /> </determine>
Copy the `Public IPv4 handle` and open a brand new browser tab/window and paste it within the handle bar.<determine class="wp-block-image size-large">
<img decoding="async" loading="lazy" width="800" top="112" src="https://ao.ms/wp-content/uploads/2022/03/6-800x112.png" alt="" class="wp-image-8768" srcset="https://ao.ms/wp-content/uploads/2022/03/6-800x112.png 800w, https://ao.ms/wp-content/uploads/2022/03/6-300x42.png 300w, https://ao.ms/wp-content/uploads/2022/03/6-768x107.png 768w, https://ao.ms/wp-content/uploads/2022/03/6-1536x214.png 1536w, https://ao.ms/wp-content/uploads/2022/03/6.png 1920w" sizes="(max-width: 800px) 100vw, 800px" /> </determine>
The occasion is now up and working and serving HTTP site visitors on port 80.