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

时间:2015-05-24 22:20:18

标签: amazon-web-services go docker elastic-beanstalk

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):

$ 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("WOOOOOOOOOOOO")

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.

2 个答案:

答案 0 :(得分:1)

我认为api是从Github上的副本构建的,而不是从本地副本构建的。 fmt包的最新提交没有无关的log语句。此外,main.go中的fmt.Fprintf语句也可以正常工作,api包中的api也是如此。尝试验证api包是从您认为的来源构建的。

EDIT 6/1/2015:

我的所有测试都表明这是一个问题源于内部子包,远程服务有问题。 fmt.Print包不是从本地副本构建的。 main.go GetIP工作得很好,将apimain包转移到fmt包,让api打印到stdout就好了网络请求。

基本上,对本地godep go build子包所做的所有更改都会被忽略。

EB日志可能会说明远程下载哪些软件包;我做了。

我不是Godep专业人士,所以也许Godep专业人士可以详细说明。但是FWIW似乎可能与extension切线相关。远程服务没有with open("file.txt", 'r') as sfile: lines = sfile.read() rows = lines.split('\n') for columns in rows: items = columns.split(' ') print items[0] 构建也可能存在问题,但就像我说的那样,我不是Godep pro,所以我不确定。

答案 1 :(得分:0)

你可能正在运行旧版本的应用程序,当我尝试在本地构建容器时,我收到以下错误:

➜ 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”我相信。