Reputation: 876
I'm not sure why, but from time to time - once in 20 lambda calls, I receive an error:
Connection timed out after 120000ms
the calls are done from ECS container, and all (caller and lambda) are written in node.js.
what should I check?
Upvotes: 3
Views: 3991
Reputation: 31
for me it was not ocassionally, but like for one time to another :S.
Somehow, one of my network devices was deactivated (PANGP Virtual Ethernet Adapter), so I re-activated it worked out
Best!
Upvotes: 0
Reputation: 1026
I know this is an old post, but I'll write how I solved a situation with the same error message in a lambda that I was working on. I hope this helps someone with a similar issue.
In my case, I also have a web app inside an EC2 which calls a lambda through lambda.invoke()
(npm aws-sdk). Both EC2 and lambda runs on Node.JS. Even though the error is logged inside the EC2, the message is thrown by the lambda itself to the caller (EC2).
My lambda makes ~3,000 requests to an API, what takes ~5 minutes (300,000 ms) to get all responses back. It seems that the lambda Node.JS runtime is keeping a socket alive during the lambda execution, which is higher than 120,000 ms (2 minutes). As the lambda code keeps running for more than this threshold, the runtime throws the error, and the lambda return a callback with it.
According to aws js sdk, the AWS object has one parameter for the http timeout:
httpOptions (map) — A set of options to pass to the low-level HTTP request. Currently supported options are:
- timeout [Integer] — Sets the socket to timeout after timeout milliseconds of inactivity on the socket. Defaults to two minutes (120000).
After I changed this configuration to 360,000 ms (6 minutes), the lambda executes successfully. So you can just set this parameter to a higher value, according to your needs:
AWS.config.update({httpOptions: {timeout: 360000}});
Upvotes: 6