Skip to content

[TestServer] Fix 488 and add simple test lambda #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2025
Merged
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
23 changes: 17 additions & 6 deletions Sources/AWSLambdaRuntimeCore/Lambda+LocalServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -352,33 +352,44 @@ private struct LambdaHTTPServer {
// :requestID/response endpoint is called by the lambda posting the response
case (.POST, let url) where url.hasSuffix(Consts.postResponseURLSuffix):
let parts = head.uri.split(separator: "/")
guard let requestId = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
guard let requestID = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
// the request is malformed, since we were expecting a requestId in the path
return .init(status: .badRequest)
}
// enqueue the lambda function response to be served as response to the client /invoke
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestId)"])
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestID)"])
await self.responsePool.push(
LocalServerResponse(
id: requestId,
id: requestID,
status: .ok,
headers: [("Content-Type", "application/json")],
body: body
)
)

// tell the Lambda function we accepted the response
return .init(id: requestId, status: .accepted)
return .init(id: requestID, status: .accepted)

// :requestID/error endpoint is called by the lambda posting an error response
// we accept all requestID and we do not handle the body, we just acknowledge the request
case (.POST, let url) where url.hasSuffix(Consts.postErrorURLSuffix):
let parts = head.uri.split(separator: "/")
guard let _ = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
guard let requestID = parts.count > 2 ? String(parts[parts.count - 2]) : nil else {
// the request is malformed, since we were expecting a requestId in the path
return .init(status: .badRequest)
}
return .init(status: .ok)
// enqueue the lambda function response to be served as response to the client /invoke
logger.trace("/:requestID/response received response", metadata: ["requestId": "\(requestID)"])
await self.responsePool.push(
LocalServerResponse(
id: requestID,
status: .internalServerError,
headers: [("Content-Type", "application/json")],
body: body
)
)

return .init(status: .accepted)

// unknown call
default:
Expand Down
Loading