Serverless Go Web Services using AWS

by AlphaGeek

Sun, Feb 19, 2017

Go Webservices

Writing web services in Go is terrific! The language is natively compiled and therefore is wicked fast; concurrency is a first class language feature in Go; and there are mature web service frameworks in Go. One of those webservice frameworks in Goa. It is a design first web services framework that generates most of the glue and scaffolding needed to run services in Go for you and lets you concentrate on the business logic.

AWS Serverless Technology

I was developing an application for use on one of my other websites and I started thinking how I was going to deploy the Go webservice I was developing as the backend to a beer recipe builder I was writing in Angular2 on the frontend. I have recently taken a liking to the idea of serverless technology for situations where it is not cost effective. See Hosting a Static Website for Pennies a Month. So I did not want to have to get back into the business of maintaining a server to run this simple webservice. I already knew that API Gateway could be backed up by AWS Lambdas but I didn’t want to write my webservice in any of the languages supported by AWS Lambda (Java, Python, & JavaScript/NodeJS). Then I found eawsy/aws-lambda-go and I decided to see if I could use it to run my API.

My Solution

I ended up developing what I call the AWS API to Lambda Shim. The ReadMe describes in great detail how to use it to server up a simple API so I will not repeat that here. However, the possibilities here are amazing. Go has such a quick startup time that even with no “warming”, the service returns in milliseconds. Once warmed, I expect performance to be quite good. I will be conducting some stress testing on this in the future and I promise to report the results here. The lambda function can backup any number of API endpoints. Amazon maintains a very robust Go implementation of their API allowing the Go based Lambda functions to perform a myriad of functions in the AWS ecosystem.