0

I have a lambda function written in python that runs a signal processing algorithm with data provided by an iOS application.

The iOS app invokes the function successfully, but after a while gets a time out error:

Session task failed with error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x282711350 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask .<6>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask .<6>" ), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=https://mylambdaURL/invocations, NSErrorFailingURLKey=https://mylambdaURL/invocations, _kCFStreamErrorDomainKey=4}

I invoke the function like this:

lambdaInvoker.invokeFunction("myLambdaName", jsonObject: jsonObject)
            .continueWith(block: {(task:AWSTask<AnyObject>) -> Any? in

                if( task.error != nil) {
                    print("Error: \(task.error!)")
                    lambdaLogs.errors += 1
                    return nil
                }
                if let JSONDictionary = task.result as? NSDictionary {
                    lambdaLogs.responses += 1
                }
                return nil
            })

However, the logs for the Lambda Function don't show any errors, the function runs successfully and even writes in a dynamoDB table without issues. So Lambda isn't timing out, however, the function runs for around 60s.

This error occurs for around half of the times the lambda is invoked.

Any ideas?

EDIT:

I tried increasing the NSURLSession timeout for request doing this in appDelegate:

let urlconfig = URLSessionConfiguration.default
urlconfig.timeoutIntervalForRequest = 300

but I still get the timeouts and the maximum run time for the lambda function was 70s, so I'm thinking I'm not really setting the correct timeoutIntervalForRequest

Danf
  • 1,409
  • 2
  • 21
  • 39
  • So you're saying your Lambda runs successfully all the time, correct? It is not hitting its allocated run time timeout then? How does your app invoke the Lambda function? Is it sitting behind an API Gateway? – Milan Cermak Jan 29 '19 at 13:15
  • Yes, the function runs successfully all the time without timing out. And I'm doing a direct invocation, I'll add that to the question! – Danf Jan 29 '19 at 13:17
  • 1
    Then I'd say it's just your NSURLSession that's timing out. Have you tried increasing its request timeout? – Milan Cermak Jan 29 '19 at 13:21
  • No I haven't, I don't know how to do that though, I'll find out and try it! – Danf Jan 29 '19 at 15:47
  • @MilanCermak, I tried doing that, but as I point out in the edit, I think I'm not doing it properly... – Danf Jan 29 '19 at 16:48
  • 2
    Are you using the shared URLSession? That one is non-configurable. You have to either create a custom session with your configuration or alternatively, set the timeout on URLRequest. See e.g. https://stackoverflow.com/questions/23428793/nsurlsession-how-to-increase-time-out-for-url-requests on how to do the former. – Milan Cermak Jan 29 '19 at 21:38
  • The thing is I don't know how to invoke the lambda function using a custom session. As you see in the code above, there is no parameter to do this and I couldn't find a way to initialize lambdaInvoker with a different config than "default"... – Danf Jan 30 '19 at 11:52
  • 1
    My Swift is somewhat rusty, but try something like this https://gist.github.com/milancermak/3b5ddb77feaa454a51b3d66dc29793f8 You need to customize the timeout on the service configuration, which inherits from the networking configuration; see https://github.com/aws-amplify/aws-sdk-ios/blob/master/AWSCore/Service/AWSService.h and https://github.com/aws-amplify/aws-sdk-ios/blob/6ab2982040eaca984eab38e311b98c3b9227b773/AWSCore/Networking/AWSNetworking.h if I didn't get it completely right. – Milan Cermak Jan 30 '19 at 13:36

0 Answers0