From 5d588914c334cf8fa6020f9307c86086e103cbe2 Mon Sep 17 00:00:00 2001 From: Andrea Scuderi Date: Sat, 3 Aug 2019 20:27:30 +0100 Subject: [PATCH 1/3] Fix: Random Crash #9 --- Sources/AWSLambdaSwift/Runtime.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/AWSLambdaSwift/Runtime.swift b/Sources/AWSLambdaSwift/Runtime.swift index 01f565b..780c70e 100644 --- a/Sources/AWSLambdaSwift/Runtime.swift +++ b/Sources/AWSLambdaSwift/Runtime.swift @@ -65,7 +65,7 @@ public class Runtime { let errorMessage = String(describing: error) let invocationError = InvocationError(errorMessage: errorMessage) let jsonEncoder = JSONEncoder() - let httpBody = try! jsonEncoder.encode(invocationError) + let httpBody = try? jsonEncoder.encode(invocationError) let postInvocationErrorEndpoint = URL(string: "http://\(awsLambdaRuntimeAPI)/2018-06-01/runtime/invocation/\(requestId)/error")! var urlRequest = URLRequest(url: postInvocationErrorEndpoint) From 3f7d56a0533485793183af233ea17ffa9d57491a Mon Sep 17 00:00:00 2001 From: Andrea Scuderi Date: Sat, 3 Aug 2019 22:37:02 +0100 Subject: [PATCH 2/3] Fix: ErrorResponse --- Sources/AWSLambdaSwift/Runtime.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/AWSLambdaSwift/Runtime.swift b/Sources/AWSLambdaSwift/Runtime.swift index 780c70e..17afe1b 100644 --- a/Sources/AWSLambdaSwift/Runtime.swift +++ b/Sources/AWSLambdaSwift/Runtime.swift @@ -11,6 +11,7 @@ public typealias JSONDictionary = [String: Any] struct InvocationError: Codable { let errorMessage: String + let errorType: String } public class Runtime { @@ -62,8 +63,9 @@ public class Runtime { } func postInvocationError(for requestId: String, error: Error) { - let errorMessage = String(describing: error) - let invocationError = InvocationError(errorMessage: errorMessage) + let errorMessage = error.localizedDescription + let invocationError = InvocationError(errorMessage: errorMessage, + errorType: "PostInvocationError") let jsonEncoder = JSONEncoder() let httpBody = try? jsonEncoder.encode(invocationError) From 8f07cafcd97fa75c09106ed5f707c6cfa763efb9 Mon Sep 17 00:00:00 2001 From: Andrea Scuderi Date: Sun, 4 Aug 2019 12:14:32 +0100 Subject: [PATCH 3/3] Fix: Random Crash #9 --- Examples/SquareNumber/Sources/SquareNumber/main.swift | 11 +++++++---- Sources/AWSLambdaSwift/Runtime.swift | 7 ++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Examples/SquareNumber/Sources/SquareNumber/main.swift b/Examples/SquareNumber/Sources/SquareNumber/main.swift index 3635a13..dfe90f6 100644 --- a/Examples/SquareNumber/Sources/SquareNumber/main.swift +++ b/Examples/SquareNumber/Sources/SquareNumber/main.swift @@ -12,7 +12,10 @@ func squareNumber(input: Input, context: Context) -> Output { let squaredNumber = input.number * input.number return Output(result: squaredNumber) } - -let runtime = try Runtime() -runtime.registerLambda("squareNumber", handlerFunction: squareNumber) -try runtime.start() +do { + let runtime = try Runtime() + runtime.registerLambda("squareNumber", handlerFunction: squareNumber) + try runtime.start() +} catch (let error) { + log(error) +} diff --git a/Sources/AWSLambdaSwift/Runtime.swift b/Sources/AWSLambdaSwift/Runtime.swift index 17afe1b..14c4121 100644 --- a/Sources/AWSLambdaSwift/Runtime.swift +++ b/Sources/AWSLambdaSwift/Runtime.swift @@ -21,7 +21,12 @@ public class Runtime { var handlers: [String: Handler] public init() throws { - self.urlSession = URLSession(configuration: .default) + + let configuration = URLSessionConfiguration.default + configuration.timeoutIntervalForRequest = 3600 + + + self.urlSession = URLSession(configuration: configuration) self.handlers = [:] let environment = ProcessInfo.processInfo.environment