title: Invoking multiple AWS Lambdas doesn't make paralel processes
body: <p>I am trying to invoke multiple lambda functions (one lambda function, that would run separate parallel processes) from another lambda function. The first one runs as cron lambda that just queries docs from db and then invokes another lambda with doc's params. This cron lambda runs every five minutes and queries the docs correctly. I was testing the second lambda with two documents. The problem is that every time the second lambda gets invoked it only process one document - every time it processes the other one it didn't process on the previous invoke:</p>
  <p>Ex:</p>
  <ul>
  <li>doc 1</li>
  <li>doc 2</li>
  </ul>
  <p>First, invoke of second lambda -&gt; process doc 1</p>
  <p>Second, invoke of second lambda -&gt; process doc 2</p>
  <p>Third, invoke of second lambda -&gt; process doc 1</p>
  <p>Forth invoke of second lambda -&gt; process doc 2</p>
  <p>etc...</p>
  <p>First (cron) lambda code:</p>
  <pre><code>aws.config.update({
    region : env.lambdaRegion,
    accessKeyId: env.lambdaAccessKeyId,
    secretAccessKey: env.lambdaSecretAccessKey,
  });
  
  const lambda = new aws.Lambda({
    region: env.lambdaRegion,
  });
  
  exports.handler = async (event: any, context: any) =&gt; {
    context.callbackWaitsForEmptyEventLoop = false;
  
    return new Promise(async (resolve, reject) =&gt; {
      for (let i = 0; i &lt; 100; i++) {
        const doc = await mongo.db.collection('docs').
          findOneAndUpdate(
            {
              status: 1,
              lambdaProcessing: null,
            },
            { $set: { lambdaProcessing: new Date() } },
            {
              sort: { processedAt: 1 },
              returnNewDocument: true,
            },
          );
  
        if (doc.value &amp;&amp; doc.value._id) {
          const params = {
            FunctionName: env.lambdaName,
            InvocationType: 'Event',
            Payload: JSON.stringify({ docId: doc.value._id }),
          };
  
          lambda.invoke(params);
        } else {
          if (doc.lastErrorObject &amp;&amp; doc.lastErrorObject.n === 0) {
            break;
          }
        }
      }
      resolve();
    });
  };
  </code></pre>
  <p>Second lambda function:</p>
  <pre><code>exports.handler = async (event: any, ctx: any) =&gt; {
    ctx.callbackWaitsForEmptyEventLoop = false;
  
    if (event &amp;&amp; event.docId) {
      const doc = await mongo.db.collection('docs').findById(event.docId);
      return await processDoc(doc);
    } else {
      throw new Error('doc ID is not present.');
    }
  };
  </code></pre>