Auto Scaling Group


We’ll create Auto Scaling Group (ASG), under EC2, and stress machines to see how auto-scaling works in action.

Let’s create:

We then stress the instance to increase the load above 20% for 4 minutes, this triggers creating another instance automatically per auto-scaler:

sudo amazon-linux-extras install epel -y
sudo yum install stress -y
#Stress the CPU with four worker threads for 320 seconds
sudo stress --cpu 4 --timeout 320

To install node and express on a new EC2 instance

curl -o- | bash
. ~/.nvm/
nvm install 16

Then install express and ip:

mkdir eduapp
cd eduapp/
npm install --save express
npm install --save ip
cat > index.js << EOF

put this in index.js:

const express = require('express');
var ip = require("ip");

const app = express();
const PORT = process.env.PORT || 3000;

app.get('/',(req, res) => res.send(ip.address()));
app.listen(PORT, () => console.log('Server listening at port 3000'))