My Lambda function returns errors sometimes when call an API. (there is 2 different APIs that Lambda calls in same time)
There is very interesting that I put some console.log's before start API call but when Lambda starts it's return error immediately without printing any log and getting 2 type errors:
{
“errorType”: “Runtime.UnhandledPromiseRejection”,
“errorMessage”: “Error: socket hang up”,
“trace”: [
“Runtime.UnhandledPromiseRejection: Error: socket hang up”,
” at process.<anonymous> (/var/runtime/index.js:35:15)“,
” at process.emit (events.js:310:20)“,
” at processPromiseRejections (internal/process/promises.js:209:33)“,
” at processTicksAndRejections (internal/process/task_queues.js:98:32)”
]
}
{
“errorType”: “Runtime.UnhandledPromiseRejection”,
“errorMessage”: “Error: Client network socket disconnected before secure TLS connection was established”,
“trace”: [
“Runtime.UnhandledPromiseRejection: Error: Client network socket disconnected before secure TLS connection was established”,
” at process.<anonymous> (/var/runtime/index.js:35:15)“,
” at process.emit (events.js:310:20)“,
” at processPromiseRejections (internal/process/promises.js:209:33)“,
” at processTicksAndRejections (internal/process/task_queues.js:98:32)”
]
}
Note1: API is another Lambda function with same domain with proxy in Api Gateway but I checked that API always returns data as expected.
Note2: where is no any logs in CloudWatch based on this error.
Note3: Lambda running on Node v12, RAM is more that 3000 MB, and timeout is 60 seconds.
Note4: I commented one of 2 API's and right now getting below error:
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "Error: read ECONNRESET",
"trace": [
"Runtime.UnhandledPromiseRejection: Error: read ECONNRESET",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:310:20)",
" at processPromiseRejections
(internal/process/promises.js:209:33)",
" at processTicksAndRejections
(internal/process/task_queues.js:98:32)"
]
}
Handler:
'use strict'
console.log("in APP 1");
const awsServerlessExpress = require('aws-serverless-express');
console.log("APP 2");
//express app
const app = require('./start-server');
console.log("in APP 3");
const binaryMimeTypes = [
'application/json',
'text/html',
];
console.log("in APP 4");
const server = awsServerlessExpress.createServer(app,null,binaryMimeTypes);
console.log("in APP 5");
exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context)
Note5:
I can reach to APIs bu url always (as I tested right now there is no problem in responses but maybe 10 minutes later returns error, who knows) but I start to test in Api gateway in AWS panel and sometimes start getting below error:
Endpoint response body before transformations: {"Message":null}
I'm not really sure that Lambda is a stable platform.
In this Lambda I'm using ExpressJS and using Sequelize as ORM.