简体   繁体   English

使用Java的AWS Lambda-设置配置连接/套接字超时

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

See here: AWS Documentation 请参阅此处: AWS文档

The connection timeout is the amount of time (in milliseconds) that the HTTP connection will wait to establish a connection before giving up. 连接超时是HTTP连接在放弃之前将等待建立连接的时间(以毫秒为单位)。 The default is 50,000 ms. 默认值为50,000毫秒。 To set this value yourself, use the ClientConfiguration.setConnectionTimeout method. 要自己设置此值,请使用ClientConfiguration.setConnectionTimeout方法。

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. 问题是,我正在尝试从AWS Lambda Java函数中更新此值。 If I am calling an external lambda function, I can configure this before I make the call. 如果要调用外部lambda函数,则可以在进行调用之前对其进行配置。 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? 有没有一种方法可以添加环境变量或以编程方式从自身内部更新当前的AWS Lambda Java函数连接和套接字超时?

Further clarification: 进一步澄清:

There is not a "client" invoking this lambda function. 没有“客户端”调用此lambda函数。 It is intended to be scheduled on the hour, triggered by the event type "CloudWatch Events - Schedule." 它打算按小时安排,由事件类型“ 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. lambda本身发出一个GET调用的请求,该调用可能需要65到140秒才能运行。 The overall lambda time is currently extended to 5 minutes. 目前,整个lambda时间已延长至5分钟。 The lambda's GET call fails right at the 50 second mark. lambda的GET调用在50秒标记处失败。 The provided AWS documentation above references a default 50 second limit, with 3 retry attempts, both of which supposedly can be modified. 上面提供的AWS文档引用了默认的50秒限制,并尝试了3次重试,这两个尝试都可以修改。 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. 但是,我无法通过lambda自己的代码或lambda本身上的任何参数以编程方式修改连接或套接字超时。 There has to be a way to configure this properly. 必须有一种正确配置此方法的方法。

To an external service, over HTTPS. 通过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. 在Postman中,任何输入或限制都需要65+秒。

Please advise. 请指教。

I found the issue. 我发现了问题。 It turns out the lambda was successful from the AWS console. 事实证明,lambda在AWS控制台中是成功的。 It was only failing in Eclipse. 它只是在Eclipse中失败。 The AWS Toolkit containing the AWS SDK gave this error: 包含AWS开发工具包的AWS工具包给出了以下错误:

com.amazonaws.SdkClientException: Unable to execute HTTP request: Read timed out com.amazonaws.SdkClientException:无法执行HTTP请求:读取超时

I made the code and AWS console changes described above, and it did not work. 我进行了上面描述的代码和AWS控制台更改,但没有用。 What it was a setting in the AWS Toolkit > Preferences as shown here: 此处显示的是AWS Toolkit>首选项中的设置:

AWS Toolkit首选项

超时配置

The above Timeouts were both set to 20000s, limiting the HTTPS calls I was making as described above. 上面的超时都设置为20000,限制了我如上所述进行的HTTPS调用。 I updated this value comically high to test it, now it resolves in about 93s. 我将该值更新为可笑的高值以对其进行测试,现在它的解析时间约为93s。 The same call in that time period from Postman is also 93s. 在那个时期内,来自邮递员的相同呼叫也是93s。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM