使用Java的AWS Lambda-设置配置连接/套接字超时 [英] AWS Lambda using Java - setting the configuration connection/socket timeouts

查看:423
本文介绍了使用Java的AWS Lambda-设置配置连接/套接字超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅此处: AWS文档

连接超时是指时间(以毫秒为单位) HTTP连接将等待建立连接,然后再给予 向上.默认值为50,000毫秒.要自己设置此值,请使用 ClientConfiguration.setConnectionTimeout方法.

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);

问题是,我正在尝试从AWS Lambda Java函数中更新此值.如果我要调用外部lambda函数,则可以在进行调用之前对其进行配置.这就是所有文档所显示的示例.

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.

是否可以通过自身添加环境变量以编程方式更新当前的AWS Lambda Java函数连接和套接字超时?

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?

进一步的说明:

没有客户";调用此lambda函数.它旨在按事件类型"CloudWatch Events-Schedule"触发的每小时进行安排. Lambda本身发出一个GET调用的请求,该调用可能需要65到140秒才能运行.目前,整个lambda时间已延长至5分钟. lambda的GET调用在50秒标记处失败.上面提供的AWS文档引用了默认的50秒限制,并尝试了3次重试,这两个尝试都可以修改.但是,我无法从lambda自己的代码或lambda本身上的任何参数以编程方式修改连接或套接字超时.必须有一种正确配置此方法的方法.

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.

通过HTTPS到外部服务.我输入了代理设置,并验证了连接正确并且是正确的呼叫.在Postman中,任何输入或限制都需要65秒钟以上的时间.

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.

请告知.

推荐答案

我发现了问题.事实证明,lambda在AWS控制台中是成功的.它只是在Eclipse中失败.包含AWS开发工具包的AWS工具包出现以下错误:

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:无法执行HTTP请求:读取超时

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

我进行了如上所述的代码和AWS控制台更改,但没有用.此处显示的是AWS Toolkit>首选项中的设置:

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:

以上超时都设置为20000,限制了我如上所述进行的HTTPS调用.我将该值更新为可笑的高值以对其进行测试,现在它的解析时间约为93s.那个时期来自邮递员的相同呼叫也是93s.

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.

这篇关于使用Java的AWS Lambda-设置配置连接/套接字超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆