I am trying to use a shell script I have in order to automate the installation of squid proxy on a single AWS server as I boot the server up using nodejs via the AWS SDK, but it seems whenever I boot the instance up the server does not take input from my script at all. Any help would be appreciated.
const AWS = require('aws-sdk')
const ec2 = new AWS.EC2({ apiVersion: '2016-11-15', region: "us-east-1", accessKeyId: "XXXXXXXXX", secretAccessKey:"XXXXXXXXXXXX" })
let commands = [
'#!/bin/bash',
'#',
'# Ubuntu 14 LTS',
'#',
'set - v',
'sudo su -',
' nano squid.sh',
'chmod + x squid.sh',
'apt - get - y update',
'apt - get install - y ntpdate',
'apt - get install - y squid3 apache2 - utils',
'cp / etc / squid / squid.conf / etc / squid / squid.conf.bak',
'cat << EOF > /etc/squid / squid.conf',
'http_port 1052',
'http_access allow all',
'cache deny all',
'forwarded_for delete',
'request_header_access Via deny all',
'EOF',
'service squid restart',
'echo "IP ADDRESS"',
'curl ifconfig.co'
];
const params = {
ImageId: 'ami-08bc77a2c7eb2b1da',
InstanceType: 't3.nano',
MinCount: 1,
MaxCount: 1,
SubnetId: 'subnet-1885ea36',
UserData:new Buffer.from(commands.join("\n")).toString('base64'),
Placement: {
Tenancy: 'dedicated',
}
};
ec2.runInstances(params, function (err, data) {
if (err) {
console.log('Could not create instance', err);
return;
}
const instanceId = data.Instances[0].InstanceId;
console.log('Created instance', instanceId);
});