Deploying a simple GoLang Application to AWS Elastic Beanstalk

I am beginner to GoLang and trying to deploy a GoLang simple application to AWS Elastic Beanstalk.
I Created a new application on AWS with t2.micro instance.
The url for my github repo is

I set my aws credentials by setting up “AWS_CREDENTIAL_FILE” environment variable.
The entire my source code is present “application.go” file.
The results of “eb init” command prompts me to select the “AWS Region” and “application”, while
"eb deploy" executes without errors.
But, as the deployment finishes my AWS server health goes to degraded, and i get “Bad Gateway” while
running application in browser.

I searched a lot of stuff to explore what the issue is, but failed. Please somebody help me to figure out this problem and tell me workflow of deploying a simple GoLang App to AWS Elastic Beanstalk.

There are two things.

For the building part:

set GOOS=linux
set GOARCH=amd64
go build -o bin\application .

For the health check (also configure the instance:

http.HandleFunc("/health", // or whatever url you wish 
	func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "OK")

Thank you Egon… i created bin/application zip file and set
GOOS=linux , GOARCH=amd64 , CGO_ENABLED=0. But i still have the same issue.

I ran into the same issue and just got this working, so I thought I would share the answer. These steps make it so that AWS will build your go application, so you don’t need to build it and upload the binary (I’m actually not sure how to make that work anyway).

  1. Your ./application.go file looks good, the key is listening on port 5000.
  2. Create a file called ./ and run chmod +x on it (it can be called anything really), with the following contents:
    go get
    go build -o bin/application application.go
  3. Create a file called ./Buildfile (this file name matters), with the following contents:
    make: ./
  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,, 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).

You can look at the logs from Elastic Beanstalk to help troubleshoot if you run into issues, but this worked for me.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.