title: NodeJS API Async/Await issue: AWS SDK
body: <p>Thank you for taking time to read this post. I am struggling to get AWS API call working with nodejs API using await.</p>
  <p>Below is my sample application which when run without the AWS SDK call works as expected. Await call work and Flags in console.log are printed in sequence.</p>
  <pre><code>var AWS = require(&quot;aws-sdk&quot;);
  const express = require('express')
  const app = express()
  const port = 8080
  
  AWS.config.update({region: &quot;us-west-2&quot;});
  
  var translate = new AWS.Translate();
  
  app.get('/', async function (req, res){
    var tt= await getText();
    console.log(&quot;Flag 2 : &quot;+tt);
   res.send('Hello World! : '+ tt)
  })
  
  app.listen(port, () =&gt; {
    console.log(`Example app listening on port ${port}`)
  })
  
  function getText()
  {
    console.log(&quot;Flag 1 : success&quot;);
    return &quot;data&quot;;// successful response
   
  }
  </code></pre>
  <p>Output:</p>
  <p>Debugger attached.</p>
  <p>Example app listening on port 8080</p>
  <p>Flag 1 : success</p>
  <p>Flag 2 : data</p>
  <p>================</p>
  <p>When I add AWS SDK API call to the mix everything goes for a toss.</p>
  <pre><code>var AWS = require(&quot;aws-sdk&quot;);
  const express = require('express')
  const app = express()
  const port = 8080
  
  AWS.config.update({region: &quot;us-west-2&quot;});
  
  var translate = new AWS.Translate();
  
  var text ;
  
  app.get('/', async function (req, res){
    await getText();
    console.log(&quot;Flag 2 : &quot;+ text);
   res.send('Hello World! : '+ text);
  })
  
  app.listen(port, () =&gt; {
    console.log(`Example app listening on port ${port}`)
  })
  
  function getText()
  
  {
  
  var params = {
    SourceLanguageCode: 'auto',
    TargetLanguageCode: 'fr',
    Text: 'Hello! Good day.'
  };
  
   translate.translateText(params, function (err, data) {
    if (err) console.log(err, err.stack); 
    else     console.log(&quot;Flag 1 : &quot;+data.TranslatedText);
          return data.TranslatedText;
  });
  
  }
  </code></pre>
  <p>Output:</p>
  <p>Debugger attached.</p>
  <p>Example app listening on port 8080</p>
  <p>Flag 2 : undefined</p>
  <p>Flag 1 : Bonjour ! Bonne journée.</p>
  <p>===========</p>
  <p>Flags are coming in incorrect order and Flag 2 is null. How do I pass the value from AWS SDK API call back to my parent function so I can return that in the API response.</p>