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 https://github.com/awaisss/goapp6.
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.
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).
Your ./application.go file looks good, the key is listening on port 5000.
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/gorilla/mux go build -o bin/application application.go
Create a file called ./Buildfile (this file name matters), with the following contents: make: ./build.sh
Create a file called ./Procfile (this file name also matters), with the following contents: web: bin/application
Zip your files together (application.go, build.sh, Buildfile, Procfile) and deploy it to AWS Elastic Beanstalk.
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.