0

I have an app written in Go, which I attempted to deploy to EB. When trying to access it, I get an Error 502 from nginx, presumably because the app is not running.

Looking at logs, I get a lot of errors like

14:01:29 build.1 | application.go:10:2: cannot find package "github.com/aws/aws-sdk-go/aws" in any of:
14:01:29 build.1 |  /opt/elasticbeanstalk/lib/go/src/github.com/aws/aws-sdk-go/aws (from $GOROOT)
14:01:29 build.1 |  /var/app/current/src/github.com/aws/aws-sdk-go/aws (from $GOPATH)

Despite the fact, that I have all of my dependencies included in the application bundle under a vendor subdirectory. How come EB does not use vendoring? According to the dashboard, it is running Go 1.9, so vendoring should be supported.

timedt
  • 1,302
  • 2
  • 9
  • 14

1 Answers1

1

You need to set your GOPATH in your EBS to the root of your project directory, assuming there is a src directory where your vendor directory is located.

For instance, pretend this is your project structure:

app/
    src/
        vendor/

And pretend that project is located in ~/home, which makes its location ~/home/app.

Then your GOPATH should be set to ~/home/app. Go will attempt to access the dependencies through $GOPATH/src/vendor.


But if this were the kind of structure you were using before, then you would need to have your GOPATH updated during local development as well, so if you aren't already doing that then I imagine you're using a different kind of setup... this solution, however, will work as long as your project is structured as I described above.

Lansana Camara
  • 9,497
  • 11
  • 47
  • 87
  • EB needs to have an `application.go` in the root of the source bundle, so my structure has source code in `$GOPATH/src/myapp` locally, and there is a `vendor` directory in there, next to `application.go` – timedt Mar 15 '18 at 15:48
  • I'm not super familiar with EBS, but is there a way you can specify a different location for the `application.go`? That would solve this problem. I think there is a way, pretty sure I've used it before, just don't remember on the top of my head. – Lansana Camara Mar 15 '18 at 16:04
  • Yes, using a Buildfile and Procfile, I was able to convert my project layout. Now it just doesn't start the app... Thank you for the answer – timedt Mar 15 '18 at 17:21
  • No problem! Glad it worked. Now for starting the application, is there a line in the Buildfile/Procfile that is similar to the `CMD` part of a Dockerfile (if you've used docker before)? In other words, is there a part that you can specify an action to run on start? Maybe that is where you can run your binaries. – Lansana Camara Mar 15 '18 at 17:31
  • 1
    It was just some issue with the working directory, that crashed the app on startup. Thanks for the extra effort, though :) – timedt Mar 15 '18 at 19:49