Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Examples/SquareNumber/Sources/SquareNumber/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 11 additions & 4 deletions Sources/AWSLambdaSwift/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public typealias JSONDictionary = [String: Any]

struct InvocationError: Codable {
let errorMessage: String
let errorType: String
}

public class Runtime {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down