title: A bash script that will start when the EC2 instance is turned on
body: <p>I have a EC2 instance, and I would like to write a script (never done them before) so that every time I start my E2 instance in the AWS console, the following files are run automatically.</p>
  
  <p>Lets say I have a file called <code>example.js</code> which contains this:</p>
  
  <pre><code>var test(){
  console.log('hello world');
  }
  test()
  </code></pre>
  
  <p>And then I have a similar file called <code>example2.js</code></p>
  
  <p>Everytime I run my EC2 instance, I need to ssh into it and do <code>node example.js</code> and <code>node example2.js</code> in order to run the functions.</p>
  
  <p>However, I would like to write a startup script so that when the EC2 instance state is turned to running (i.e. online), I would like the command <code>node example.js</code> and <code>node example2.js</code> executed by themselves. </p>
  
  <p>Is this possible? If yes, where do I put this script?</p>
  
  <p>I have a Centos image running on my EC2 instance, and the EC2 instance is turned off at night, and turned back on in the morning - hence the script will simplify things! </p>
  
  <p>I read this link, however cannot quite figure it out in my case: <a href="http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html" rel="nofollow noreferrer">http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html</a></p>
  
  <p>Any help will be appreciated. Thanks </p>