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

huangapple go评论85阅读模式
英文:

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

问题

这是一个比较深入的问题,我会尽力解释清楚。

我使用Go构建了一个小型的API服务,现在我想使用相对较新的AWS Elastic Beanstalk Docker支持将其部署到AWS上。

以下是我所做的事情(代码都是开源的,所以你可以跟着操作):

$ 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应用程序,我将看到显示我的公共IP地址(这是正确的行为),所以我知道我的应用程序正在运行/可用。

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

fmt.Println("WOOOOOOOOOOOO")

上述语句只是将"WOO..."打印到控制台。每次发出新请求时都会运行这个语句。

不幸的是,当我运行eb logs查看我的实例日志时,这个调试行从未显示出来,我无法弄清楚原因。

我尝试过打印到STDERR,打印到STDOUT等等,但是我完全无法获得任何输出。

我已经在互联网上搜索解决方案,但还没有找到任何解决办法。

英文:

This is sort of an in-depth question, so I'll try to explain it as best I can.

I've built a small API service in Go that I'm trying to deploy to AWS using the relatively new AWS Elastic Beanstalk Docker support.

Here's what I've done (the code is all open source, so you can follow along if you'd like):

<!-- language: lang-sh -->

$ 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

This will use elastic beanstalk to create a new app (with docker), and deploy it.

If I then run eb open
to open my web app, I'll see my public IP address displayed (this is the correct behavior), so I know that my application is running / functional.

Now, in my source code, I've got several lines of debugging output:

fmt.Println(&quot;WOOOOOOOOOOOO&quot;)

The above statement just prints "WOO…" to the console. This is run every time a new request is made.

Unfortunately, when I run eb logs to view my instance logs, this debug line never shows up – and I can't figure out why.

I've tried printing to STDERR, printing to STDOUT, etc. – but I'm absolutely unable to get any output.

I've scoured the internet looking for solutions, but have yet to find any.

答案1

得分: 1

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

编辑于6/1/2015:

我所有的测试都表明,这是一个由于存在内部子包而导致的问题,远程服务对此有问题。api包没有从本地副本构建。main.go中的fmt.Print可以正常工作,并且将GetIPapi包移动到main包可以让fmt在Web请求期间正常打印到标准输出。

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

EB日志可能会显示有关哪些包被远程下载的信息;我的日志中有这样的信息。

我不是Godep专家,所以也许一个Godep专家可以详细说明。但是值得一提的是,这似乎与这个问题有关,间接地。这也可能是远程服务在构建时没有使用godep go build导致的问题,但是像我说的,我不是Godep专家,所以我不确定。

英文:

I think import &quot;github.com/rdegges/ipify-api/api&quot; is being built from the copy on Github, not from the local copy. The most recent commit of the api package doesn't have the extraneous fmt statements. Also, the log statement in main.go works fine, as does the fmt.Fprintf already in the api package. Try to verify the api package is getting built from the source you think it is.

EDIT 6/1/2015:

All my tests indicate this is a problem stemming from having an internal subpackage, and the remote service having trouble with that. The api package is not getting built from the local copy. fmt.Print works just fine from main.go, and moving GetIP from the api package to the main package lets fmt print just fine to stdout during web requests.

Basically, all changes made to the local api subpackage are getting ignored.

The EB logs probably say something about which packages are being downloaded remotely; mine did.

I'm not a Godep pro, so maybe a Godep pro can elaborate. But FWIW, it seems like it might be related to this issue, tangentially. It might also be a problem with the remote service not building with godep go build, but like I said, I'm not a Godep pro, so I'm unsure.

答案2

得分: 0

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

➜ docker build .

执行 3 个构建触发器

触发器 0,COPY . /go/src/app
步骤 0:COPY . /go/src/app
触发器 1,RUN go-wrapper download
步骤 0:RUN go-wrapper download
---> 正在运行 c1854666d13c

  • exec go get -v -d
    github.com/julienschmidt/httprouter (下载)
    github.com/rdegges/ipify-api (下载)
    github.com/rs/cors (下载)
    触发器 2,RUN go-wrapper install
    步骤 0:RUN go-wrapper install
    ---> 正在运行 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: 无法将 api.NotFound(类型为 func(http.ResponseWriter, *http.Request))分配给类型 http.Handler:
func(http.ResponseWriter, *http.Request) 不实现 http.Handler(缺少 ServeHTTP 方法)
./main.go:28: 无法将 api.MethodNotAllowed(类型为 func(http.ResponseWriter, *http.Request))分配给类型 http.Handler:
func(http.ResponseWriter, *http.Request) 不实现 http.Handler(缺少 ServeHTTP 方法)
命令 '/bin/sh -c go-wrapper install' 返回了非零代码:2

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

英文:

It is possible you are running an older version of the app, when I try to build the container locally I get the following error:

➜ 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
 ---&gt; 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
 ---&gt; 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 &#39;/bin/sh -c go-wrapper install&#39; returned a non-zero code: 2

Are there any errors in your event stream after you deploy? "eb events" i believe.

huangapple
  • 本文由 发表于 2015年5月25日 06:20:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/30428926.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定