[英]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
這將使用彈性beanstalk創建一個新的應用程序(與docker),並部署它。
如果我然后eb open
我的網絡應用程序,我會看到我的公共IP地址顯示(這是正確的行為),所以我知道我的應用程序正在運行/功能。
現在,在我的源代碼中,我有幾行調試輸出:
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
包是從您認為的源構建的。
編輯6/1/2015:
我的所有測試表明,這是一個問題源於內部子包,遠程服務有問題。 api
包不是從本地副本構建的。 fmt.Print
工作得很好,從main.go
和移動GetIP
從api
包到main
包讓fmt
打印就好在Web請求到標准輸出。
基本上,對本地api
子包進行的所有更改都會被忽略。
EB日志可能會說明遠程下載哪些軟件包; 我做了。
我不是Godep職業選手,所以也許Godep職業選手可以詳細說明。 但是FWIW似乎可能與這個問題有關。 這也可能是遠程服務沒有使用godep go build
,但就像我說的那樣,我不是Godep pro,所以我不確定。
您可能正在運行舊版本的應用程序,當我嘗試在本地構建容器時,我收到以下錯誤:
➜ 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”我相信。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.