簡體   English   中英

如何處理 nodejs 中的 AWS lambda 函數錯誤

[英]How to handle the AWS lambda function error in nodejs

我正在使用節點 js 從服務器獲取 HTTPS 響應。 響應包含超過 6291556 個字節當我執行這個函數時,我得到了以下異常。 有沒有最好的方法來處理錯誤

{
  "errorMessage": "Response payload size exceeded the maximum allowed payload size (6291556 bytes).",
  "errorType": "Function.ResponseSizeTooLarge"
}

示例代碼

var res = await beResult(event.id);
    
      const response = {
          statusCode: 200,
          body: res,
      };
      return response;
    };
    
    async function beResult(id) {
      const url = "https://api.com/request/";    
      const params = {
          method: "GET",
          mode: "cors",
          headers: {
          "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
          "Content-Type": "application/json",
          }
      };
      const urlId= url + id;
      return await fetch(urlId, params).then(res => res.json())
      .then(json => { return json;});
    }

AWS Lambda 函數對請求和響應大小有限制。

您可以在開發人員指南的Lambda 配額頁面上了解它們。

調用負載(請求和響應)

  • 6 MB(同步)
  • 256 KB(異步)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM