Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Beanstalk Procfile for go

I'm trying to deploy my go restful server program to EC2 Linux using Elastic Beanstalk. The document says that I need to create a Procfile at the root. So I did. Here are the steps:

  1. Build my go program myapp.go to using

    $ go build -o myapp -i myapp.go
    
  2. Create a Procfile with exact name at the root with

    web: myapp
    
  3. Zip up the Procfile and the myapp image to a myapp.zip file.

Upload to the server via Elastic Beanstalk console. But I keep getting Degraded health and warning with

WARN Process termination taking longer than 10 seconds.

Any suggestions. By the way, I tried to use the same procfile procedure on the simple application.go zip file came from the Elastic Beanstalk example library. It didn't work either.

like image 894
Gary Avatar asked Sep 03 '25 02:09

Gary


1 Answers

I was finally able to get a Go application to deploy with Elastic Beanstalk using the eb client. There are a few things that EB requires:

  1. The name of your main file should be application.go.
  2. Make sure your app is listening on port 5000.
  3. You'll need a Procfile in the main root with

    web: bin/application
    
  4. You'll need a Buildfile with

    make: ./build.sh
    
  5. And finally you'll need a build.sh file with

    #!/usr/bin/env bash
    # Stops the process if something fails
    set -xe
    
    # All of the dependencies needed/fetched for your project. 
    # FOR EXAMPLE:
    go get "github.com/gin-gonic/gin"
    
    # create the application binary that eb uses
    GOOS=linux GOARCH=amd64 go build -o bin/application -ldflags="-s -w"
    

Then if you run eb deploy (after creating your initial eb repository), it should work. I wrote a whole tutorial for deploying a Gin application on EB here. The section specifically on deploying with Elastic Beanstalk is here.

like image 58
Linz Jax Avatar answered Sep 04 '25 16:09

Linz Jax