Closed sebsto closed 1 month ago
@tomerd wdyt ? (probably worth to squash the commits :-) )
Thank you @MahdiBM for your suggestions - they are all in.
@tomerd should we reconsider merging this one too ?
@sebsto I believe https://github.com/swift-server/swift-aws-lambda-runtime/pull/315/files#r1429195527 needs to be addressed first
@tomerd done.
I merged the two statements with a if logger.logLevel <= .trace
as you suggested and I sliced the buffer to print only the first Kb
Hello @tomerd Ar ewe good to merge with this last comment ? Or you still prefer code to enforce the content type ?
According to the AWS Lambda service API documentation, the payload is always a string https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html
This PR adds a
logger.trace()
inLambdaRuntime
just before calling user's handler. It allows to see in the trace logs a string representation of the event passed by the AWS Service.Motivation:
When there is no or poor documentation of the event passed to a lambda function, is it super hard to figure out the exact
Codable
struct to implement for theLambdaHandler
.With other programming languages, such as Python or Typescript, developers typically add a
print(event)
orconsole.log(event)
at the start of the lambda handler function to figure out the exact type of data to deal with.When using the Swift AWS Lambda Runtime, it's not possible because the bytes received are encoded to a
struct
before the user's code is called.When there is a mismatch between the received bytes and the
Codable
struct, the user is left with very few information to figure out what was wrong. Theencode()
error messages are cryptic. They don't provide enough information to debug this type of error.Modifications:
I added one line in
LambdaRuntime
to trace a string representation of the request before calling the user's handler.I also modified the README to document the use of the LOG_LEVEL environemnt variable. While I was modifying the README, I noticed there was no mention of local test, I therefore added a small section about local testing (which is a subject related to this PR, hence a single PR for the two new sections in the README)
Result:
When invoking the runtime with
LOG_LEVEL=trace
, we receive information such as