title: Get Value Back from AWS lambda.invoke synchronously
body: <p>I'm attempting to call an AWS Lambda function from another Lambda function using the <code>invoke</code> method with a <code>RequestResponse</code> invocation type and retrieve a value returned from the Lambda.</p>
  
  <p>When I call the <code>lambda.invoke</code> using <code>await</code> the callback still appears to be called asynchronously. I'd like for the values I need to be available on the next line of code, hence the synchronous requirement. However, in the code below in the logs I see the "Data out of Callback" entry occur prior to the "Data in Callback" entry with a 0 value out of the callback and a correct value in the callback.</p>
  
  <p>If anyone could help me understand how to accomplish this I would greatly appreciate it! Here's the code:</p>
  
  <pre><code>async readData() {
  
          let myData = [];
  
          const params = {
              FunctionName: "MyFunctionName",
              InvocationType: "RequestResponse",
          };
  
          await lambda.invoke(params, (error, data) =&gt; {
              if (error) {
                  console.log("Got a lambda invoke error");
                  console.error(error);
              } else {
                  let response = JSON.parse(data.Payload);
                  myData = JSON.parse(response.body);
  
                  console.log("Data in Callback: " + myData.length);
              }
          });
  
          console.log("Data out of Callback: " + myData.length);
  }
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Chris</p>