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 01f565b..14c4121 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 { @@ -20,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 @@ -62,10 +68,11 @@ 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) + let httpBody = try? jsonEncoder.encode(invocationError) let postInvocationErrorEndpoint = URL(string: "http://\(awsLambdaRuntimeAPI)/2018-06-01/runtime/invocation/\(requestId)/error")! var urlRequest = URLRequest(url: postInvocationErrorEndpoint)