Skip to content
Closed
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
9 changes: 5 additions & 4 deletions Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ extension Lambda {
///
/// - parameters:
/// - invocationEndpoint: The endpoint to post payloads to.
/// - port: Port for local server to listen to.
/// - body: Code to run within the context of the mock server. Typically this would be a Lambda.run function call.
///
/// - note: This API is designed stricly for local testing and is behind a DEBUG flag
public static func withLocalServer(invocationEndpoint: String? = nil, _ body: @escaping () -> Void) throws {
let server = LocalLambda.Server(invocationEndpoint: invocationEndpoint)
public static func withLocalServer(invocationEndpoint: String? = nil, port: Int? = nil, _ body: @escaping () -> Void) throws {
let server = LocalLambda.Server(invocationEndpoint: invocationEndpoint, port: port)
try server.start().wait()
defer { try! server.stop() } // FIXME:
body()
Expand All @@ -53,14 +54,14 @@ private enum LocalLambda {
private let port: Int
private let invocationEndpoint: String

public init(invocationEndpoint: String?) {
public init(invocationEndpoint: String?, port: Int?) {
let configuration = Lambda.Configuration()
var logger = Logger(label: "LocalLambdaServer")
logger.logLevel = configuration.general.logLevel
self.logger = logger
self.group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
self.host = configuration.runtimeEngine.ip
self.port = configuration.runtimeEngine.port
self.port = port ?? configuration.runtimeEngine.port
self.invocationEndpoint = invocationEndpoint ?? "/invoke"
}

Expand Down