douwu8251 2018-05-19 07:44
浏览 23
已采纳

是否可以打印错误?

For example such code:

os.Stderr.WriteString(rec.(string))

But this will not show as an error: aws lambda monitoring

I know that I can panic after logging and catch it on API Gateway (against sending stacktrace to the client) - no other ways? Documentation is not mention anything like that.

  • 写回答

1条回答 默认 最新

  • doumigu9594 2018-05-19 11:06
    关注

    It seems not possible. I assume, you're looking at the metrics in Amazon CloudWatch

    AWS Lambda automatically monitors functions on your behalf, reporting metrics through Amazon CloudWatch. These metrics include total invocations, errors, duration, throttles, DLQ errors and Iterator age for stream-based invocations. https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-metrics.html

    Now, let's see how do they define errors

    Metric "Errors" measures the number of invocations that failed due to errors in the function (response code 4XX).

    So, if you want to see the errors on that graph, you have to respond with the proper codes. If you're concerned about exposing the error stacktrace, here is a good read Error handling with API Gateway and Go Lambda functions. The basic idea there is about creating a custom lambdaError type, meant to be used by a Lambda handler function to wrap errors before returning them. This custom error message

    {
      "code": "TASK_NOT_FOUND",
      "public_message": "Task not found",
      "private_message": "unknown task: foo-bar"
    }
    

    will be wrapped in a standard one

    {
      "errorMessage": "{\"code\":\"TASK_NOT_FOUND\",\"public_message\":\"Task not found\",\"private_message\":\"unknown task: foo-bar\"}",
      "errorType": "lambdaError"
    }
    

    and later on mapped in API Gateway, so, the end client will see only the public message

    {
      "code": "TASK_NOT_FOUND",
      "message": "Task not found"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名