# Deploying a simple GoLang Application to AWS Elastic Beanstalk

**URL:** <https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696>\
**Category:** Getting Help\
**Created:** [October 19, 2016, 12:34pm UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696 "2016-10-19T12:34:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![awais](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@awais](https://forum.golangbridge.org/u/awais)\
**Post date:** [October 19, 2016, 12:34pm UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696/1 "2016-10-19T12:34:23Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![Egon](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/egon/32/627_2.png) [@Egon](https://forum.golangbridge.org/u/Egon)\
**Post date:** [October 19, 2016, 3:01pm UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696/2 "2016-10-19T15:01:34Z")

</div>

There are two things.

- The zip should contain a binary, not the source file. [https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html#go-simple-apps](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-environment.html#go-simple-apps). So also zip the bin directory… If you are running on Windows you also need to specify that you want to build for linux.
- Provide a proper health end-point for your service.

For the building part:

```auto
set GOOS=linux
set GOARCH=amd64
set CGO_ENABLED=0
go build -o bin\application .

```

For the health check (also configure the instance:

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

```

---

<div class="post-metadata">

**Author:** ![awais](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@awais](https://forum.golangbridge.org/u/awais)\
**Post date:** [October 20, 2016, 5:39am UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696/3 "2016-10-20T05:39:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![az\_dev](https://forum.golangbridge.org/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@az\_dev](https://forum.golangbridge.org/u/az_dev)\
**Post date:** [October 23, 2016, 9:46pm UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696/4 "2016-10-23T21:46:48Z")

</div>

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 ./build.sh and run chmod +x on it (it can be called anything really), with the following contents:  
_go get [github.com/gorilla/mux](http://github.com/gorilla/mux)_  
_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](http://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).

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [January 21, 2017, 9:47pm UTC](https://forum.golangbridge.org/t/deploying-a-simple-golang-application-to-aws-elastic-beanstalk/3696/5 "2017-01-21T21:47:14Z")

</div>

Closed on January 21, 2017, 9:47pm UTC

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