Deploying a simple GoLang Application to AWS Elastic Beanstalk (echo framework)

  1. Create ./application.go start server at port 5000
package main
import (
 “net/http”
 “github.com/Sirupsen/logrus”
 “github.com/labstack/echo”
)
func init() {
 logrus.SetLevel(logrus.DebugLevel)
 logrus.SetFormatter(&logrus.JSONFormatter{})
}
func main() {
 e := echo.New()
 e.GET(“/”, func(c echo.Context) error {
 return c.String(http.StatusOK, “Hello, World!”)
 })
 e.Logger.Fatal(e.Start(“:5000”))
}

2. Create a file called ./build.sh and run chmod +x on it (it can be called anything really), with the following contents:

go get github.com/Sirupsen/logrus
go get github.com/labstack/echo
go build -o bin/application application.go

3. Create a file called ./Buildfile (this file name matters), with the following contents:

make: ./build.sh

4. Create a file called ./Procfile (this file name also matters), with the following contents:

web: bin/application

5. Zip your files together (application.go, build.sh, Buildfile, Procfile) and deploy it to AWS Elastic Beanstalk.

6. Your instance health should change to OK and you should be able to hit your web service now on port 80 (ngnix will map the request to your go app listening on port 5000).

Resources:

https://echo.labstack.com/

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html