2018-04-13 04:09
浏览 234


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?

图片转代码服务由CSDN问答提供 功能建议

我使用无服务器框架创建了一个简单的Go Lambda来玩。 我希望(根据文档) fmt.Println log.Println 的所有输出都将显示在Cloudwatch中。 但是我看不到。


  func Handler(request events.APIGatewayProxyRequest)(事件。  APIGatewayProxyResponse,错误){

我确定权限是 正确,因为我看到了日志组,并且有Cloudwatch条目可供查看此lambda。 我实际上可以看到在CloudFormation中创建的日志组,所以我确定这不是问题所在。 但是我只是没有在CloudWatch中看到任何 Println 语句的输出。 这是我要做的所看到的:

  START RequestId:fd48461b-3ecd-11e8-9e32-594932db04f2版本:$ LATEST 
END RequestId:fd48461b-  3ecd-11e8-9e32-594932db04f2 
REPORT RequestId:fd48461b-3ecd-11e8-9e32-594932db04f2持续时间:13.82 ms计费持续时间:100 ms内存大小:256 MB使用的最大内存:21 MB 

我尝试了其他各种 Print 方法(例如 Printf ),但是您不会对此没有任何改变感到惊讶。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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:

        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
        sls deploy
    install:    build deploy

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

    点赞 打赏 评论
  • dou91808 2018-04-13 05:35

    Sorry that I haven't used Lambda previously. Maybe using glog library is helpful.see the glog

    点赞 打赏 评论

相关推荐 更多相似问题