【发布时间】:2022-11-10 15:15:39
【问题描述】:
--> 我有一个带有 eventBridge 的 lambda 函数的基本设置。此函数每 2 分钟调用一次。那里我有锦标赛.txt 文件,其中有 35 个锦标赛 ID,对于每个锦标赛 ID,我从 api 获取数据。
--> 然后我使用另一个无服务器路由将这些获取的数据保存到数据库中。
现在在 cloudwatch 日志中,我的 lambda 函数给出了错误,如下图所示
我的 lambda 函数代码
const axios = require("axios");
const fs = require("fs");
const writeResult = async (id) => {
console.log(id);
try {
const res = await axios.get(`${BASE_URL}/${id}.xml?json=1`);
if (res) {
const matches = res?.data?.commentaries?.tournament?.match;
if (Array.isArray(matches)) {
await Promise.all(
matches.map(async (m) => {
try {
await axios.post(
"https:example.com//route1",
m
);
await axios.post(
"https:example.com//route2",
m
);
await axios.post(
"https:example.com//route3",
m
);
await axios.post(
"https:example.com//route4",
m
);
await axios.post(
"https:example.com//route5",
m
);
await axios.post(
"https:example.com//route6",
m
);
} catch (error) {
console.log(error.message);
}
})
);
}
} catch (error) {
console.log(error.message);
}
};
exports.handler = async () => {
const ids = fs
.readFileSync("tournaments.txt", "utf-8")
.replace(/\r/g, "")
.trim()
.split("\n");
Promise.all(
ids.map((id) => {
writeResult(id);
})
);
return "finally done";
};
这里可能的问题是什么?我做了一些研究,但没有找到任何有用的解决方案。
【问题讨论】:
标签: node.js aws-lambda