使用 Elastic Beanstalk 的 AWS 上的 Go Web 应用程序未在日志中显示输出

Go Web app on AWS with Elastic Beanstalk not showing output in logs

这是一个有深度的问题,所以我会尽力解释一下。

我在 Go 中构建了一个小型 API 服务,我正尝试使用相对较新的 AWS Elastic Beanstalk Docker support.

这是我所做的(代码都是开源的,所以如果你愿意,你可以跟着做):

$ git clone https://github.com/rdegges/ipify-api.git
$ cd ipify-api
$ git fetch origin aws:aws
$ git checkout aws
$ eb init
$ eb create
$ eb deploy

这将使用 elastic beanstalk 创建一个新应用程序(docker),并部署它。

如果我那么运行eb open 打开我的 Web 应用程序,我会看到我的 public IP 地址显示(这是正确的行为),所以我知道我的应用程序是 运行ning/功能。

现在,在我的源代码中,我有几行调试输出:

fmt.Println("WOOOOOOOOOOOO")

上面的语句只是将 "WOO…" 打印到控制台。这是每次发出新请求时 运行。

不幸的是,当我 运行 eb logs 查看我的实例日志时,此调试行从未出现 – 我不明白为什么。

我试过打印到 STDERR、打印到 STDOUT 等 – 但我绝对无法获得任何输出。

我在互联网上搜索解决方案,但还没有找到。

我认为 import "github.com/rdegges/ipify-api/api" 是从 Github 上的副本构建的,而不是从本地副本构建的。 api 包的最新提交没有多余的 fmt 语句。此外,main.go 中的 log 语句工作正常,api 包中已有的 fmt.Fprintf 也是如此。尝试验证 api 包是从您认为的来源构建的。

2015 年 6 月 1 日编辑:

我所有的测试都表明这是一个由内部子包引起的问题,而远程服务有问题。 api 包不是从本地副本构建的。 fmt.Printmain.go 开始工作得很好,将 GetIPapi 包移动到 main 包让 fmt 在期间打印到标准输出网络请求。

基本上,对本地 api 子包所做的所有更改都将被忽略。

EB 日志可能会说明正在远程下载哪些包;我有。

我不是Godep pro,所以也许Godep pro可以详细说明。但是 FWIW,似乎它可能与 this issue 切线相关。这也可能是远程服务不是使用 godep go build 构建的问题,但就像我说的,我不是 Godep 专家,所以我不确定。

可能您是 运行 应用程序的旧版本,当我尝试在本地构建容器时出现以下错误:

➜ docker build .
# Executing 3 build triggers
Trigger 0, COPY . /go/src/app
Step 0 : COPY . /go/src/app
Trigger 1, RUN go-wrapper download
Step 0 : RUN go-wrapper download
 ---> Running in c1854666d13c
+ exec go get -v -d
github.com/julienschmidt/httprouter (download)
github.com/rdegges/ipify-api (download)
github.com/rs/cors (download)
Trigger 2, RUN go-wrapper install
Step 0 : RUN go-wrapper install
 ---> Running in 0bbdec1b99d7
+ exec go install -v
github.com/julienschmidt/httprouter
github.com/rdegges/ipify-api/models
github.com/rs/cors
github.com/rdegges/ipify-api/api
app
# app
./main.go:27: cannot use api.NotFound (type func(http.ResponseWriter, *http.Request)) as type http.Handler in assignment:
    func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method)
./main.go:28: cannot use api.MethodNotAllowed (type func(http.ResponseWriter, *http.Request)) as type http.Handler in assignment:
    func(http.ResponseWriter, *http.Request) does not implement http.Handler (missing ServeHTTP method)
The command '/bin/sh -c go-wrapper install' returned a non-zero code: 2

部署后事件流中是否有任何错误? "eb events"我相信。