Skip to content

Instantly share code, notes, and snippets.

@immma
Last active September 27, 2022 04:14
Show Gist options
  • Save immma/04068c5300d6ff0adbfd2f86a1cdb889 to your computer and use it in GitHub Desktop.
Save immma/04068c5300d6ff0adbfd2f86a1cdb889 to your computer and use it in GitHub Desktop.
EC2 Bootstrap with Bootstrap CSS
#!/bin/bash
yum update -y
yum install -y httpd
ipv4=$(curl -s "http://169.254.169.254/latest/meta-data/local-ipv4")
hostname=$(curl http://169.254.169.254/latest/meta-data/local-hostname)
cat > /var/www/html/index.html << _EOF_
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<title>$ipv4 | Hello world</title>
</head>
<body>
<div class="container">
<h1>Hello world</h1>
<h3>This is ardih</h3>
<div class="row">
<div class="col">
<table class="table">
<tr>
<td><b>IP</b></td>
<td><a href="http://$ipv4" target="_blank" rel="noopener noreferrer">$ipv4</a></td>
</tr>
<tr>
<td><b>Public hostname</b></td>
<td><a href="http://$hostname" target="_blank" rel="noopener noreferrer">$hostname</a></td>
</tr>
<tr>
<td><b>Version</b></td>
<td>v.1.1</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
_EOF_
systemctl start httpd
systemctl enable httpd
#!/bin/bash
yum update -y
yum install -y httpd
public_ipv4=$(curl -s "http://169.254.169.254/latest/meta-data/public-ipv4")
hostname=$(curl http://169.254.169.254/latest/meta-data/public-hostname)
mkdir /var/www/html/v2
cat > /var/www/html/v2/index.html << _EOF_
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<title>$public_ipv4 | Hello world</title>
</head>
<body>
<div class="container">
<h1>Hello world</h1>
<h3>This is ardih</h3>
<div class="row">
<div class="col">
<table class="table">
<tr>
<td><b>IP</b></td>
<td><a href="http://$public_ipv4" target="_blank" rel="noopener noreferrer">$public_ipv4</a></td>
</tr>
<tr>
<td><b>Public hostname</b></td>
<td><a href="http://$hostname" target="_blank" rel="noopener noreferrer">$hostname</a></td>
</tr>
<tr>
<td><b>Version</b></td>
<td>v.1.2</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
_EOF_
systemctl start httpd
systemctl enable httpd
#!/bin/bash
yum update -y
yum install -y httpd
public_ipv4=$(curl -s "http://169.254.169.254/latest/meta-data/public-ipv4")
hostname=$(curl http://169.254.169.254/latest/meta-data/public-hostname)
cat > /var/www/html/index.html << _EOF_
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<title>$public_ipv4 | Hello world</title>
</head>
<body>
<div class="container">
<h1>Hello world</h1>
<h3>This is ardih</h3>
<div class="row">
<div class="col">
<table class="table">
<tr>
<td><b>IP</b></td>
<td><a href="http://$public_ipv4" target="_blank" rel="noopener noreferrer">$public_ipv4</a></td>
</tr>
<tr>
<td><b>Public hostname</b></td>
<td><a href="http://$hostname" target="_blank" rel="noopener noreferrer">$hostname</a></td>
</tr>
<tr>
<td><b>Version</b></td>
<td>v.1.1</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
_EOF_
systemctl start httpd
systemctl enable httpd
@immma
Copy link
Author

immma commented Sep 5, 2022

For testing only
Use this user data to EC2 Amazon Linux 2 with public subnet to connect with Bootstrap CSS.

To use ec2-bootstrap-private.sh please place NAT gateway to install Apache and CSS Boostrap.

Expected result
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment