I have a lambda function accessed via API gateway. The function receives username and password and performs authentication on a given active directory.
If the user is found then it calls the database to fetch the user by username > generates JWT and returns it in the response.
For last few days I have been getting CORS errors on the login page. On further inspection of the CloudWatch logs I see these errors
{
"errno": "ETIMEDOUT",
"code": "ETIMEDOUT",
"syscall": "connect",
"address": "10.1.2.39",
"port": 389
}
error.code Error: connect ETIMEDOUT 10.1.2.39:389
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
{ errno: 'ETIMEDOUT', code: 'ETIMEDOUT', syscall: 'connect', address: '10.1.2.39', port: 389}
ERROR: aws-serverless-express connection error
ERROR Error: socket hang up
at connResetException (internal/errors.js:609:14)
at Socket.socketOnEnd (_http_client.js:458:23)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) { code: 'ECONNRESET'}
The weird thing is, when I try to log into the application for the first time, I get these errors, but let's say I wait for some 15-20 minutes and then try logging again, no error appears and I am logged in smoothly.
The AD is maintained by the customer and they claim nothing is wrong on their end. This issue started happening recently even though the application has been in production for the last six months.
I am using the activedirectory module for AD authentication. If I run a simple authenticate code locally with the same username and password then it works so there is no problem with AD authentication or the credentials.
I am using Node 12 in my lambda. Also I am using aws-serverless-koa and not express so I am assuming that the error is coming from some dependency (probably activedirectory).