1
0

More than 1 year has passed since last update.

Goで書かれたLambdaのpanic時、CloudWatchLogsにスタックトレースが出ない

Posted at

現象

Goで書かれたLambdaでpanicが発生した際、CloudWatchLogsにスタックトレースが出ず、下記エラーログに固定されるため、
原因の調査が出来なくて困った。

2022/02/01 07:16:00 calling the handler function resulted in a panic, the process should exit

原因

aws-lambda-goのバージョン、v1.24.0を利用していたが、

上記だと、panic時にログに出力しない実装になっている。

解決策

aws-lambda-goのバージョンをv1.27.1に上げる。

2022/02/08 08:17:55 
{
    "errorMessage": "panic test.",
    "errorType": "string",
    "stackTrace": [
        {
            "path": "github.com/aws/aws-lambda-go@v1.27.1/lambda/errors.go",
            "line": 39,
            "label": "lambdaPanicResponse"
        }
        ~ 省略 ~
    ]
}

その他

panicをdeferを使ってエラーをキャッチする方法もあるが、これだとスタックトレースは出力出来ない。

defer func() {
        if err := recover(); err != nil {
            log.Errorf(":%v", err)
        }
    }()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0