diff --git a/ch2/bash/deploy-ec2-instance.sh b/ch2/bash/deploy-ec2-instance.sh index fbc2de9..f6b4ab3 100644 --- a/ch2/bash/deploy-ec2-instance.sh +++ b/ch2/bash/deploy-ec2-instance.sh @@ -4,7 +4,7 @@ set -e export AWS_DEFAULT_REGION="us-east-2" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -user_data=$(cat "$SCRIPT_DIR/../../ch/ec2-user-data-script/user-data.sh") +user_data=$(cat "$SCRIPT_DIR/user-data.sh") security_group_id=$(aws ec2 create-security-group \ --group-name "sample-app" \ diff --git a/ch2/bash/user-data.sh b/ch2/bash/user-data.sh new file mode 100644 index 0000000..3ea16e6 --- /dev/null +++ b/ch2/bash/user-data.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +curl -fsSL https://rpm.nodesource.com/setup_21.x | bash - +yum install -y nodejs + +tee app.js > /dev/null << "EOF" +const http = require('http'); + +const server = http.createServer((req, res) => { + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.end('Hello, World!\n'); +}); + +const port = 80; +server.listen(port,() => { + console.log(`Listening on port ${port}`); +}); +EOF + +nohup node app.js & \ No newline at end of file