【问题标题】:Client network socket disconnected before secure TLS connection was established aws lambda nodejs客户端网络套接字在建立安全 TLS 连接之前断开连接 aws lambda nodejs
【发布时间】: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


    【解决方案1】:

    我已经解决了这个问题。刚刚添加等待在 Promise.all() 之前,现在一切正常

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2020-04-22
      • 2020-08-07
      • 2021-09-15
      • 2020-09-18
      • 2020-08-06
      • 2019-05-04
      • 2021-02-25
      • 1970-01-01
      相关资源
      最近更新 更多