调用另一个(长)Lambda时,AWS Lambda超时 [英] AWS Lambda timeout when another (long) Lambda is invoked

查看:251
本文介绍了调用另一个(长)Lambda时,AWS Lambda超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用将多个Lambda链接在一起的步进函数.在这些Lambda之一中,我调用了另一个Lambda.两个Lambda都有15分钟的超时时间.但是,在经过几分钟后,调用次要Lambda的主要Lambda会超时(次要Lambda会愉快地继续其工作).

I am using Step Functions that link together multiple Lambdas. In one of these lambdas I invoke another lambda. Both lambdas have 15 min timeout. However, after some mins the primary lambda that invokes the secondary lambda times out (the secondary lambda happily continues its work).

Error

com.amazonaws.SdkClientException
Cause

{"errorMessage": "Unable to execute HTTP request: Read timed out",
  "errorType": "com.amazonaws.SdkClientException",
  "stackTrace": [
    cause": {
      "errorMessage": "Read timed out",
   "errorType": "java.net.SocketTimeoutException",
   "stackTrace": [
  "java.net.SocketInputStream.socketRead0(Native Method)",
  "java.net.SocketInputStream.socketRead(SocketInputStream.java:116)",
  "java.net.SocketInputStream.read(SocketInputStream.java:171)",
  "java.net.SocketInputStream.read(SocketInputStream.java:141)",
  "sun.security.ssl.InputRecord.readFully(InputRecord.java:465)",
  "sun.security.ssl.InputRecord.read(InputRecord.java:503)",
  "sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)",
  "sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)",
  "sun.security.ssl.AppInputStream.read(AppInputStream.java:105)",

这是代码,如您所见,我尝试使用4个不同的命令来提高超时时间.

This is the code, as you can see I try to raise the timeout using 4 different commands.

  // (2) Instantiate AWSLambdaClientBuilder to build the Lambda client
        AWSLambdaClientBuilder builder = 
 AWSLambdaClientBuilder.standard().withRegion(region);
        // (3) Build the client, which will ultimately invoke 
   the function
        AWSLambda client = builder.build();

        // (4) Create an InvokeRequest with required parameters
        InvokeRequest req = new 
   InvokeRequest().withFunctionName(random_arn).withPayload(jsonString); 

        // (5) Invoke the function and capture response
        int timeout = (15*60*1000);
        req.setSdkClientExecutionTimeout(timeout);
        req.setSdkRequestTimeout(timeout);
        req.withSdkClientExecutionTimeout(timeout);
        req.withSdkRequestTimeout(timeout);

        InvokeResult result = client.invoke(req);

有什么办法解决这个超时问题吗?

Any idea how to tackle this timeout?

推荐答案

在使用AWS Lambda时,您可能会感兴趣的超时时间不止一次.您要指的是函数执行超时-人们通常在谈论Lambda时所表示的超时.但是,您还需要配置其他超时.看看AWS CLI文档:

There is more than one timeout you might be interested when working with AWS Lambda. The one you are referring to is the function execution timeout - the timeout people usually mean while talking about Lambda. However, there are also other timeouts you want to configure. Take a look at AWS CLI docs:

https://docs.aws.amazon.com/cli/latest/reference/index.html

这里有--cli-read-timeout--cli-connect-timeout.如果我要创建一个具有5分钟函数执行超时时间的Lambda函数,并使用RequestResponse(同步)调用类型使用AWS CLI调用该函数,则发生的时间将超过1分钟(--cli-read-timeout的默认值), AWS Lambda将使此执行失败,并触发自动重试,最多重试次数.根据您的描述,我相信您正面临这种麻烦.设置所有超时,然后重试.

Here you have --cli-read-timeout and --cli-connect-timeout. If I'd create a Lambda function with say 5 mins function execution timeout, and invoke it using AWS CLI using RequestResponse (synchronous) invocation type, if it happens it takes more than 1 min to execute (default value for --cli-read-timeout), AWS Lambda will fail this execution and trigger automatic re-try, up to a max number of retries. From what you are describing, I believe you are facing that kind of trouble. Set all the timeouts and try again.

更多链接可能会有所帮助:

A few more links you may find helpful:

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

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/section-client-configuration.html

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/ClientConfiguration.html#setSocketTimeout-int-

这篇关于调用另一个(长)Lambda时,AWS Lambda超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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