#aws cloudwatch logs and go

5 messages · Page 1 of 1 (latest)

ornate thunder
#

i have an example lambda i am trying to implement based on the official aws docs

https://docs.aws.amazon.com/lambda/latest/dg/lambda-golang.html

and this hello world application

https://github.com/awsdocs/aws-lambda-developer-guide/tree/main/sample-apps/blank-go

I was able to get the lambda to execute, but I am seeing each line of the json sent as a separate cloudwatch log message. i'm not sure why. i havent seen this behavior in python, nodejs, and rust. i'm not sure how the custom lambda runtime is interpretting what go is producing from the marshal indent function. any help would be greatly appreciated.

GitHub

Supplementary resources for the AWS Lambda Developer Guide - awsdocs/aws-lambda-developer-guide

#

aws cloudwatch logs and go

valid valley
#

I recommend that you use log/slog instead. Don't indent it. Each entry should be a single line.

#

I've created an AWS Lambda function and I use slog for logging. It works just fine. Don't try to customize anything, just use the slog JSON handler.

mystic tree
#

Yeah, this is more of an AWS thing than a Go thing. (I think GCP has the same quirk in their logging.) Logs seem to be parsed from the stdout / etderr streams, and streams are newline delimited. They can't really tell the difference between a "newline as part of one print" and "newlines from different print statements".

There seems to be a multi_line_start_pattern configuration you might be able to set, if you really really must have it. But it's probably easier to just copy an in-line json into a prettifier if you need to than it is to jump through those hoops.