Go 1.6 on Elastic Beanstalk

Image for post
Image for post

AWS Elastic Beanstalk is a fantastically easy way to deploy simple to medium complexity apps with confidence and ease. We have been using it exclusively at Kounta to deploy our web application and other services.

Recently we have started creating services in Go, or at least one service in Go. Beanstalk was an obvious choice. Beanstalk does support Go but unfortunately only supports up to Go 1.4, which for a lot of us is just a tad too old.

There are a few ways to get a newer Go version on Beanstalk. You can use a preconfigured docker container or compile the app yourself as a linux executable and deploy the binary alone.

Both of these options require more work than we would have liked. We wanted to be able to specify the Go version with the deploy and change versions reliably and easily. The simple solution is to download the Go binaries as part of your deploy process.

When you deploy the application in Beanstalk make sure you select a stack that is already preconfigured for Go. At the time of writing this that was v1.4. Now you can use a Buildfile. The Buildfile(case-sensitive, sits in the root of your project) lets you run one or more custom scripts in parallel to compile your application. It is as simple as one line:

The build.sh(in this case also in the root of your project, but you can put it anywhere you like) is where all the action is at:

If you use this script as a base you really only need to be aware a few lines:

  • GOGZ=go1.6.2.linux-amd64.tar.gz: This is the name of the download, simply change this to get a different version — but make sure you specify the linux distribution.
  • DEST=$GOROOT/src/github.com/your/package: You will need to move your source into the appropriate package folder.

Originally published at http://elliot.land on July 2, 2016.

Written by

I’m a data nerd and TDD enthusiast originally from Sydney. Currently working for Uber in New York. My thoughts here are my own. 🤓 elliotchance@gmail.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store