title: DynamoDb put does not write/save to table in lambda test or cron but works in Serverless
body: <p>I am scraping a bunch of API's and saving the data to a dynamodb table.</p>
  <p>Everything works absolutely fine when running <code>serverless invoke local -f runAggregator</code> locally.</p>
  <p>However, after I set up the cron, I noticed things were not being saved to the Dynamodb table.</p>
  <p>Here is my function:</p>
  <pre class="lang-js prettyprint-override"><code>module.exports.runAggregator = async (event) =&gt; {
    await runModules({ saveJobs: true });
  
    return {
      statusCode: 200,
      body: JSON.stringify(
        {
          message: &quot;Aggregate&quot;,
          input: event,
        },
        null,
        2
      ),
    };
  };
  </code></pre>
  <p>And the <code>runModules</code> function:</p>
  <pre class="lang-js prettyprint-override"><code>module.exports = async ({ saveJobs }) =&gt; {
    if (saveJobs) {
      const flushDb = await flushDynamoDbTable();
      console.log(&quot;Flushing Database: Complete&quot;);
      console.log(flushDb);
    }
  
    // pseudo code
    const allJobs = myLongArrayOfJobsFromApis
  
    const goodJobs = allJobs.filter((job) =&gt; {
      if (job.category) {
        if (!job.category.includes(&quot;Missing map for&quot;)) return job;
      }
    });
  
    // This runs absolutely fine locally...
    if (saveJobs) goodJobs.forEach(saveJob); // see below for function
  
    const badJobs = allJobs.filter((job) =&gt; {
      if (!job.category) return job; // no role found from API
      if (job.category.includes(&quot;Missing map for&quot;)) return job;
    });
  
    console.log(&quot;Total Jobs&quot;, allJobs.length);
    console.log(&quot;Good Jobs&quot;, goodJobs.length);
    console.log(&quot;Malformed Jobs&quot;, badJobs.length);
  
    return uniqBy(badJobs, &quot;category&quot;);
  };
  </code></pre>
  <p>saveJob function</p>
  <pre class="lang-js prettyprint-override"><code>// saveJob.js
  module.exports = (job) =&gt; {
    validateJob(job);
  
    dynamoDb
      .put({
        TableName: tableName,
        Item: job,
      })
      .promise();
  };
  
  </code></pre>
  <p>I am baffled as to why this works fine locally not when I run a 'test' in the lambda console. I only found out due to the table being empty after the cron had ran.</p>