我正在使用serverless框架如果我用(serverless invoke local --function launch_scrapers
)在本地调用函数,我的代码可以正常工作,但是当我尝试在没有local
标志的情况下调用时,出现此错误< / p>
我的目标是让launch_scrapers为st.getNumOfPages()
返回的许多页面调用另一个lambda函数
{
"errorMessage": "Unexpected reserved word",
"errorType": "SyntaxError",
"stackTrace": [
"",
"SyntaxError: Unexpected reserved word",
"createScript (vm.js:80:10)",
"Object.runInThisContext (vm.js:139:10)",
"Module._compile (module.js:616:28)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/handler.js:5:12)"
]
}
Error --------------------------------------------------
Invoked function failed
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: Invoked function failed
at AwsInvoke.log (/usr/lib/node_modules/serverless/lib/plugins/aws/invoke/index.js:102:31)
From previous event:
at Object.invoke:invoke [as hook] (/usr/lib/node_modules/serverless/lib/plugins/aws/invoke/index.js:22:10)
at BbPromise.reduce (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:422:55)
From previous event:
at PluginManager.invoke (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:422:22)
at PluginManager.run (/usr/lib/node_modules/serverless/lib/classes/PluginManager.js:453:17)
at variables.populateService.then (/usr/lib/node_modules/serverless/lib/Serverless.js:109:33)
at processImmediate (internal/timers.js:443:21)
at process.topLevelDomainCallback (domain.js:136:23)
From previous event:
at Serverless.run (/usr/lib/node_modules/serverless/lib/Serverless.js:96:6)
at serverless.init.then (/usr/lib/node_modules/serverless/bin/serverless:43:28)
at /usr/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:111:16
at /usr/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:45:10
at FSReqCallback.args [as oncomplete] (fs.js:145:20)
From previous event:
at initializeErrorReporter.then (/usr/lib/node_modules/serverless/bin/serverless:43:6)
at processImmediate (internal/timers.js:443:21)
at process.topLevelDomainCallback (domain.js:136:23)
From previous event:
at /usr/lib/node_modules/serverless/bin/serverless:28:46
at Object.<anonymous> (/usr/lib/node_modules/serverless/bin/serverless:65:4)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11
这是我的handler.js
"use strict"
const deployScrapers = require("./utils")
const creds = require("./creds.json");
const st = require('./skillstream')
module.exports.launch_scrapers = async function () {
try {
await st.initialise()
await st.login(creds.username, creds.password)
// const mypage_array = await st.getNumOfPages()
const test_page_array = [20, 21, 22, 23, 24]
test_page_array.forEach(page => {
deployScrapers(page)
})
}
catch (error) {
console.log(error)
}
finally {
}
}