title: awaited Promises still returning <pending>
body: <p>I have an array of data objects about people. Each person object includes 0-n URLs for additional info (guests of the person).</p>
  
  <p>I want to process this list, calling each of the 'guest' URLs and including the guest's names in the original data set.</p>
  
  <p>Context: this is an AWS lambda function. I'm using <a href="https://www.npmjs.com/package/lambda-local" rel="nofollow noreferrer">lambda-local</a> to run this locally. (<code>lambda-local -l index.js -e fixtures/test_event1.json</code>).</p>
  
  <p>I'm successfully using await/async to retrieve the initial set of data.</p>
  
  <p>But I'm unable to get if working for these further calls about guest info. It always shows a pending Promise, even though the result is awaited.</p>
  
  <pre><code>// index.js
  
  const fetch = require('node-fetch');
  
  exports.handler = async function(event){
  
      try {
          let registrations = await getEventRegistrations();
          console.log(registrations);
  
  /* All good here - sample console output
  [ { contactId: 43452967,
      displayName: 'aaa, bbb',
      numGuests: 0,
      guestUrls: [] },
    { contactId: 43766365,
      displayName: 'bbb, ccc',
      numGuests: 1,
      guestUrls:
       [ 'https://&lt;URL&gt;' ] },
    { contactId: 43766359,
      displayName: 'ccc, ddd',
      numGuests: 2,
      guestUrls:
       [ 'https://&lt;URL&gt;',
         'https://&lt;URL&gt; ] } ]
  */
  
          // Expanding the guest URLs is proving problematic - see expandGuests function below
          registrations = registrations.map(expandGuests);
          console.log(registrations);
  
  
  /* Registrations are just pending Promises here, not the real data
  
  [ Promise { &lt;pending&gt; },
    Promise { &lt;pending&gt; },
    Promise { &lt;pending&gt; } ]
  
  */
  
          return {
              statusCode: 200,
              headers: {
                  'Access-Control-Allow-Origin': '*',
              },
              body: JSON.stringify(registrations),
          };
      }
      catch (exception) {
          console.log(exception);
          return {
              statusCode: 500,
              body: 'Unable to retrieve data.'
          };
      }
  };
  
  function getEventRegistrations() {
      return fetch('&lt;URL&gt;')
      .then(res =&gt; res.json())
      .catch(function (error) {
          console.log('Event registrants request failed', error);
          return null;
      });
  }
  
  function getGuestName(url) {
      return fetch(url)
      .then(res =&gt; res.json())
      .then(guest =&gt; guest.DisplayName)
      .catch(function (error) {
          console.log('Guest name request failed', error);
          return null;
      });
  }
  
  async function expandGuests(data) {
  
      const promises = data.guestUrls.map(url =&gt; getGuestName(url));
      data.guestNames = await Promise.all(promises);
  
      return data;
  }
  
  
  </code></pre>
  
  <p>How can I resolve these pending Promises and thus return useful data?</p>
  
  <p>Thank you.</p>