title: Node.js forEach loop of aws method
body: <p>I am trying to execute code after a forEach loop has finished, this is a simplified version of my problem:</p>
  
  <pre><code>var arr = { values: ['1', '2', '3', '4', '5'] };
  
  arr.values.forEach(function (element) {
      ec2.describeInstances({ InstanceIds: ['i-51ec7d83'] }, function (err, data) {
          console.log(data.Reservations[0].Instances[0].Tags[0].Value);
      });
  });
  
  console.log('Excecute this after.');
  </code></pre>
  
  <p>However the result is:</p>
  
  <blockquote>
    <p>Excecute this after. </p>
    
    <p>Test1 </p>
    
    <p>Test1 </p>
    
    <p>Test1 </p>
    
    <p>Test1 </p>
    
    <p>Test1</p>
  </blockquote>
  
  <p>I thought forEach loops were syncronous, why is this happening? What can I do?</p>
  
  <p>Thanks! </p>