From 40d7769fd8d3865f5bd5ebcf7fd3f9a3f25feba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 15 Nov 2024 13:11:34 +0100 Subject: [PATCH 1/4] Update local server to Swift 6 --- Package.swift | 2 +- Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 69f5ff36..d26d2042 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( .library(name: "AWSLambdaTesting", targets: ["AWSLambdaTesting"]), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio.git", from: "2.72.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.76.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"), ], targets: [ diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift index 9eed4389..39f0bbec 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift @@ -133,6 +133,10 @@ private enum LocalLambda { } func processRequest(context: ChannelHandlerContext, request: (head: HTTPRequestHead, body: ByteBuffer?)) { + + let eventLoop = context.eventLoop + let loopBoundContext = NIOLoopBound(context, eventLoop: eventLoop) + switch (request.head.method, request.head.uri) { // this endpoint is called by the client invoking the lambda case (.POST, let url) where url.hasSuffix(self.invocationEndpoint): @@ -142,6 +146,7 @@ private enum LocalLambda { let requestID = "\(DispatchTime.now().uptimeNanoseconds)" // FIXME: let promise = context.eventLoop.makePromise(of: Response.self) promise.futureResult.whenComplete { result in + let context = loopBoundContext.value switch result { case .failure(let error): self.logger.error("invocation error: \(error)") @@ -178,6 +183,7 @@ private enum LocalLambda { // create a promise that we can fullfill when we get a new task let promise = context.eventLoop.makePromise(of: Invocation.self) promise.futureResult.whenComplete { result in + let context = loopBoundContext.value switch result { case .failure(let error): self.logger.error("invocation error: \(error)") From a1337a3665ec867371389e1d3ad1c9a0bcdbb323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 15 Nov 2024 13:32:48 +0100 Subject: [PATCH 2/4] fix compilation error for local server in release mode --- Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift | 2 -- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift index 39f0bbec..a23ef1cf 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift @@ -12,8 +12,6 @@ // //===----------------------------------------------------------------------===// -// commented out as long as we have a fix for Swift 6 language mode CI - #if DEBUG import Dispatch import Logging diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 86274836..02e526da 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -76,7 +76,9 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St } else { - // we're not running on Lambda, let's start a local server for testing +#if DEBUG + // we're not running on Lambda and we're compiled in DEBUG mode, + // let's start a local server for testing try await Lambda.withLocalServer(invocationEndpoint: Lambda.env("LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT")) { @@ -92,6 +94,10 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St ) } } +#else + // in release mode, we can't start a local server because the local server code is not compiled. + throw LambdaRuntimeError(code: .missingLambdaRuntimeAPIEnvironmentVariable) +#endif } } } From c764e075a7986bd63cae16a001678d011ca240cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 15 Nov 2024 13:34:31 +0100 Subject: [PATCH 3/4] fix format --- Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift index 02e526da..c058bf3d 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaRuntime.swift @@ -76,8 +76,8 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St } else { -#if DEBUG - // we're not running on Lambda and we're compiled in DEBUG mode, + #if DEBUG + // we're not running on Lambda and we're compiled in DEBUG mode, // let's start a local server for testing try await Lambda.withLocalServer(invocationEndpoint: Lambda.env("LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT")) { @@ -94,10 +94,10 @@ public final class LambdaRuntime: @unchecked Sendable where Handler: St ) } } -#else + #else // in release mode, we can't start a local server because the local server code is not compiled. throw LambdaRuntimeError(code: .missingLambdaRuntimeAPIEnvironmentVariable) -#endif + #endif } } } From 0647fdd66a580f21467760f43b44688763df05cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 15 Nov 2024 18:01:48 +0100 Subject: [PATCH 4/4] try to fix [CI] --- .github/workflows/integration_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 35b46aa3..baf78508 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -114,7 +114,7 @@ jobs: pushd Examples/${EXAMPLE} # package the example (docker and swift toolchain are installed on the GH runner) - echo yes | swift package archive --allow-network-connections docker + LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ]