AWS Lambda using Java - setting the configuration connection/socket timeouts

微笑、不失礼 提交于 2019-12-19 12:06:09

问题


See here: AWS Documentation

The connection timeout is the amount of time (in milliseconds) that the HTTP connection will wait to establish a connection before giving up. The default is 50,000 ms. To set this value yourself, use the ClientConfiguration.setConnectionTimeout method.

I am trying to set the value myself, using:

ClientConfiguration configuration = new ClientConfiguration();
configuration.setConnectionTimeout(1900000);
configuration.setSocketTimeout(1900000);

Problem is, I am trying to update this value FROM WITHIN an AWS Lambda Java function. If I am calling an external lambda function, I can configure this before I make the call. This is what all of the documentation is showing examples of.

Is there a way I can add an environment variable or programmatically update the current AWS Lambda Java function connection and socket timeout from within itself?

Further clarification:

There is not a "client" invoking this lambda function. It is intended to be scheduled on the hour, triggered by the event type "CloudWatch Events - Schedule." The lambda itself places a request for one GET call that can take anywhere from 65 seconds to 140 seconds to run. The overall lambda time is currently extended to 5 minutes. The lambda's GET call fails right at the 50 second mark. The provided AWS documentation above references a default 50 second limit, with 3 retry attempts, both of which supposedly can be modified. However, I have been unable to modify the connection or socket timeout programmatically from the lambda's own code, or any parameter on the lambda itself. There has to be a way to configure this properly.

To an external service, over HTTPS. I fed it proxy settings and I verified the connection was correct and that it was the right call. In Postman, it takes 65+ seconds for any input or limit.

Please advise.


回答1:


I found the issue. It turns out the lambda was successful from the AWS console. It was only failing in Eclipse. The AWS Toolkit containing the AWS SDK gave this error:

com.amazonaws.SdkClientException: Unable to execute HTTP request: Read timed out

I made the code and AWS console changes described above, and it did not work. What it was a setting in the AWS Toolkit > Preferences as shown here:

The above Timeouts were both set to 20000s, limiting the HTTPS calls I was making as described above. I updated this value comically high to test it, now it resolves in about 93s. The same call in that time period from Postman is also 93s.



来源:https://stackoverflow.com/questions/48958499/aws-lambda-using-java-setting-the-configuration-connection-socket-timeouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!