我已经部署了一个lambda函数,该函数调用另一个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)"
]
}
这是我的handler.js
scrapeData
函数由launch_scrapers调用的,用于获取它们的许多数据页面,现在我仅使用一个小数组进行测试
"use strict"
const deployScrapers = require("./utils")
const creds = require("./creds.json");
const st = require('./scraper')
module.exports.scrapeData = async function (page_num) {
try {
await st.initialise()
await st.login(creds.username, creds.password)
const data = await st.getJsonData(page_num)
await st.pushToDB(data)
return {
statusCode: 200,
body: JSON.stringify('Hello from scrapeData'),
};
}
catch (error) {
console.log(error)
}
finally {
}
}
module.exports.launch_scrapers = async function () {
try {
await st.initialise()
await st.login(creds.username, creds.password)
// const page_array = await st.getNumOfPages()
const test_page_array = [20, 21, 22, 23, 24]
test_page_array.forEach(page => {
console.log(page)
deployScrapers(page)
})
}
catch (error) {
console.log(error)
}
finally {
}
}
,然后在我的deployScrapers.js
const AWS = require("aws-sdk");
module.exports = async function (pageNum) {
try {
const lambda = await new AWS.Lambda({
region: "eu-west-2"
});
const params = await {
FunctionName: "lambda-node-dev-scrapeData",
InvocationType: "Event",
LogType: "Tail",
Payload: JSON.stringify(pageNum)
};
return await lambda.invoke(params, function (error, data) {
console.log("Deployed scraper page " + pageNum)
if (error) {
console.error(JSON.stringify(error));
return new Error(`Error scraping: ${JSON.stringify(error)}`);
} else if (data) {
console.log(data);
return JSON.stringify(data);
}
}).promise()
}
catch (error) {
console.log(error)
}
finally {
}
}