部署简单的Go Web应用到Elastic Beanstalk

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

Deploy Simple Go Webapp to Elastic Beanstalk

问题

我正在尝试通过 Elastic Beanstalk(通过 UI)部署一个 Go 应用程序。

我已经完成的工作:

  • 创建了一个名为 application.go 的单个文件,它监听端口 5000。
  • 使用以下命令将其编译为 Linux(设置 GOOS=linux 和 GOARCH=amd64):https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html
    • go build -o bin/application application.go
  • 将 bin 文件夹压缩并上传到 Elastic Beanstalk(我也尝试过不带 bin 文件夹的上传文件)。

开发环境中,我使用的是 go 版本 go1.18.1 windows/amd64。

在 Elastic Beanstalk 的平台中,我看到:Go 1 运行在 64 位 Amazon Linux 2/3.5.1 上。

根据 https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go,go v. 1.18.1 是受支持的。

我的代码:

package main
import (
    "fmt"
    "net/http"
    "time"
)
func main() {
    http.HandleFunc("/", index)
    fmt.Println("Now serving!!!")
    http.ListenAndServe(":5000", nil)
}
func index(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "My Res !!! %s", time.Now())
}

应用程序的健康状态为 "no data"。

最近的事件是 "环境健康状态从 Pending 转换为 No Data。没有任何实例发送数据。"

当我在 Chrome 开发工具中尝试打开链接时,我只得到 (failed) net:ERR_CONNECTION_RESET。"Failed to load response data: No Resource with given identifier found"

可能的问题:

  • 当我查看配置选项卡时,我发现此环境不属于 VPC。这可能是问题吗?

一些可能的下一步操作:

  • 在 WSL 上进行测试运行
  • 在独立的 EC2 上进行测试部署
  • 尝试通过 CLI 进行部署
  • 尝试将其包装在 Docker 容器中并进行部署(尽管这不会解决我的问题,但我希望能够在没有 Docker 的情况下进行部署)
英文:

I am trying to deploy a Go app to Elastic beanstalk (through the UI)

What I've done:

  • Created a single application.go file which listens on Port 5000
  • Compiled for Linux (set GOOS=linux and GOARCH=amd64) using the command found here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html
    • go build -o bin/application application.go
  • zipped the bin folder and uploaded it to Elastic Beanstalk (I've also tried uploading the file without the bin folder)

For development I'm using go version go1.18.1 windows/amd64

Under Platform in Elastic Beanstalk I see: Go 1 running on 64bit Amazon Linux 2/3.5.1

According to https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.go
go v. 1.18.1 is supported

My Code:

package main
import (
    "fmt"
    "net/http"
    "time"
)
func main() {
    http.HandleFunc("/", index)
    fmt.Println("Now serving!!!")
    http.ListenAndServe(":5000", nil)
}
func index(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "My Res !!! %s", time.Now())
}

The Application health is "no data".

With the most recent event of "Environment health has transitioned from Pending to No Data. None of the instances are sending data."

When I look in chrome dev tools and try to open the link, I just get (failed) net:ERR_CONNECTION_RESET. "Failed to load response data: No Resource with given identifier found"

Potential Issues:

  • When I look at the configuration tab, I see that this environment is not part of a VPC. Could that be the issue?

Some Potential Next Steps:

  • Test running on WSL
  • Test deploying on a standalone EC2
  • Try deploying through the CLI
  • Try wrapping in a docker container and deploying docker (though this wouldn't actually solve my problem, I'd like to be able to deploy without docker)

答案1

得分: 1

我尝试使用你的代码复制了你的问题,但是一切正常。我的 EB 环境可以正常运行并且使用你的代码进行部署。

我唯一能想到的是我使用的是 Linux 来创建二进制文件,而你使用的是 windows/amd64。我认为这些二进制文件是不可互换的。

英文:

I tried to replicate your issue using your code, but everything is fine. My EB environment works and deploys perfectly with your code.

The only thing I can think of is that I used linux to create my binary, while you've used windows/amd64. I don't think those binaries are interchangeable.

huangapple
  • 本文由 发表于 2022年5月3日 07:53:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/72093532.html
匿名

发表评论

匿名网友

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

确定