You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Serverless Framework调度AWS定时任务出现TypeError: e is not a function错误

Fixing "e is not a function" Error in Serverless AWS Scheduled Task

Hey there, that TypeError: e is not a function error is a common gotcha when setting up Serverless handlers—let's break down what's going wrong and fix it quickly.

What's Causing the Issue?

Looking at your tasks.js file, the problem is right here:

const analyticsTask = require('./src/tasks/analytics.task');
module.exports.analytics = analyticsTask.run();

When you add () to analyticsTask.run(), you're immediately executing the function when the module loads, not passing the function itself as the handler. Since your run function doesn't return anything, the exported analytics ends up being undefined—and Serverless Framework expects a function to handle the Lambda invocation, hence the "not a function" error.

Step-by-Step Fix

1. Update the Handler Export in tasks.js

Remove the parentheses after run to export the function reference instead of its execution result:

const analyticsTask = require('./src/tasks/analytics.task');
// Export the function itself, not the result of running it
module.exports.analytics = analyticsTask.run;

While your test code works for logging, in production you should call the callback to properly terminate the Lambda function and avoid timeouts:

module.exports.run = (event, context, callback) => { 
  console.log('Getting data...'); 
  console.log('success');
  // Signal task completion to Lambda
  callback(null, 'Analytics task executed successfully');
};

3. Test or Redeploy

  • For local testing, run:
    serverless invoke local -f analyticsDataProcess
    
  • To deploy the fix to AWS, run:
    serverless deploy
    

Your scheduled task should now run without the TypeError!

内容的提问来源于stack exchange,提问作者Anuj TBE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:28:45