You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Go应用到AWS Elastic Beanstalk时持续构建失败的问题排查求助

部署Go应用到AWS Elastic Beanstalk时持续构建失败的问题排查求助

大家好,我最近在尝试把一个Go应用部署到AWS Elastic Beanstalk,但一直卡在构建失败的环节,试了各种配置都没解决,想请大家帮忙看看问题出在哪。

遇到的核心错误

我主要碰到两类报错:

  1. 找不到应用二进制文件:

2023/10/31 14:01:25.797145 [ERROR] An error occurred during execution of command [app-deploy] - [Check Procfile For Golang Application]. Stop running the command. Error: no application binary from source

  1. 构建脚本执行失败:

2023/11/01 17:31:03.667171 [ERROR] An error occurred during execution of command [app-deploy] - [Golang Specific Build Application]. Stop running the command. Error: build application failed on command ./build.sh with error: startProcess Failure: starting process "make" failed: Command /bin/sh -c systemctl start make.service failed with error exit status 1. Stderr:Job for make.service failed because the control process exited with error code.
See "systemctl status make.service" and "journalctl -xeu make.service" for details.

我的项目配置与尝试过程

我已经做了一个最小可复现的GitLab仓库(里面包含部署用的zip包),下面是我试过的各种配置和操作:

目录结构尝试

我先后试了三种目录结构:

  • 结构一:
.ebextensions/          # 存放配置文件的目录
portal/                 # 应用代码目录,包含application.go
.env                    # 环境变量文件
Buildfile
Procfile
build.sh
go.mod
go.sum
application             # 本地预生成的二进制文件
  • 结构二(把二进制文件放到bin子目录):
.ebextensions/
portal/
.env
Buildfile
Procfile
build.sh
go.mod
go.sum
bin/application         # 二进制文件
  • 结构三:把application.go直接放在项目根目录,其他配置文件也在根目录

但不管哪种结构,部署都会报错。

配置文件内容

  • Buildfile:
make: ./build.sh
  • Procfile(最初版本):
web: application
  • build.sh:
#!/usr/bin/env bash

# 安装依赖
go get ./...

# 构建应用
go build -o application portal/application.go

其他尝试

  • 我试过直接打包根目录的关键文件:zip dist.zip .ebextenstions Buildfile Procfile build.sh application,部署后出现构建脚本执行失败的错误。
  • 后来修改Procfile为make: chmod +x build.sh; ./build.sh,还是遇到同样的make.service启动失败的错误。
  • 之前我成功用Docker容器部署过这个Go应用,但因为要给单实例配置HTTPS,尝试用.ebextensions配置没生效(上传Dockerrun.aws.json后配置不生效,也试过把.ebextensions和Dockerrun文件一起打包,还是不行),所以才转成非Docker的部署方式。

我的疑问

根据AWS官方文档,部署Go应用满足以下任一条件就可以:

  1. 项目根目录下有application.go文件
  2. 根目录或bin目录下有命名为application的二进制文件

但我两种情况都试过了,还是报找不到二进制或者构建失败的错误,实在搞不清哪里漏了,有没有朋友遇到过类似的问题,或者能帮我指出配置里的问题?

备注:内容来源于stack exchange,提问作者Alfie Danger

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 09:44:32