dos71253 2018-04-13 04:09
浏览 333
已采纳

fmt.Println输出未显示在CloudWatch日志中

I created a simple Go Lambda to play with, using the Serverless framework. I expected (as per the documentation) that all output from fmt.Println or log.Println would show up in Cloudwatch. But I don't see it.

Here's an example of a line I put in purely for testing purposes:

func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
    fmt.Println("Hello from lambda")

    (...)

I'm certain the permissions are correct, because I see the log-group, and there are Cloudwatch entries to view for this lambda. I can actually see the log-group being created in CloudFormation, so I'm sure that's not the issue. But I just don't see the output from any Println statements in CloudWatch. This is what I do see:

START RequestId: fd48461b-3ecd-11e8-9e32-594932db04f2 Version: $LATEST
END RequestId: fd48461b-3ecd-11e8-9e32-594932db04f2
REPORT RequestId: fd48461b-3ecd-11e8-9e32-594932db04f2  Duration: 13.82 ms  Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 21 MB  

I've tried various other Print methods (like Printf), but you won't be surprised that didn't change anything.

What am I missing?

  • 写回答

2条回答 默认 最新

  • doushitang4276 2018-04-13 09:17
    关注

    Well, that's embarrassing... Of course, you need to run make before running an sls deploy... If you don't do that, you'll always be deploying stale code. I'll forgive myself, because it's only my second day at Go, but it's silly all the same.

    I have updated my Makefile by adding deploy and install, like so:

    build:
        dep ensure
        env GOOS=linux go build -ldflags="-s -w" -o bin/hello hello/main.go
        env GOOS=linux go build -ldflags="-s -w" -o bin/world world/main.go
    
    deploy:
        sls deploy
    
    install:    build deploy
    

    make install now builds, then deploys, preventing this issue from happening again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?