Go Kit (1) – A Go framework for AWS Lambda

A Go framework for AWS Lambda

In previous posts I discussed why I think Lambda represents a new development opportunity. Lambda based services are operationally aware by design. Delegating some operational responsibility to AWS frees your team to focus on creating business value at higher velocity. Earlier PaSS offerings promised similar benefits, but those often didn’t materialize for a host of reasons. Lambda-based architectures provide a significantly different abstraction (FaSS — Functions as a Service?) that truly moves application development towards #LessOps.

This lofty pronouncement is nice and everything, but idle speculation is worth the pixels it costs. To promote the broader adoption of AWS Lambda (and Go, for that matter), I’ve released Sparta: a (opinionated) Go framework for AWS Lambda microservices.

This post provides a brief introduction to Sparta, including primary design goals and a simple Sparta application. Sparta is written in Go, which AWS Lambda doesn’t officially support. Isn’t AWS Lambda already a big enough shift? Why Go?

Go cloud, young people

Sparta shield


Sparta is a framework that transforms a standard go application into a self-deploying AWS Lambda powered service. All configuration and infrastructure requirements are expressed as go types – no JSON or YAML needed!


1. Define 

// File: application.go
package main

import (
  sparta "github.com/mweagle/Sparta"

// Hello world event handler
func helloWorld() (string, error) {
	return "Hello World 🌏", nil

// Main
func main() {
  var lambdaFunctions []*sparta.LambdaAWSInfo
  lambdaFn := sparta.HandleAWSLambda("Hello world test",
  lambdaFunctions = append(lambdaFunctions, lambdaFn)

  // Delegate to Sparta
		"Simple Sparta application that creates a single AWS Lambda function",

2. Deploy 

$ go run main.go provision --s3Bucket MY_S3_BUCKET
[0000]  INFO ════════════════════════════════════════════════
[0000]  INFO ╔═╗┌─┐┌─┐┬─┐┌┬┐┌─┐   Version : 1.1.1
[0000]  INFO ╚═╗├─┘├─┤├┬┘ │ ├─┤   SHA     : beb5700
[0000]  INFO ╚═╝┴  ┴ ┴┴└─ ┴ ┴ ┴   Go      : go1.10
[0000]  INFO ════════════════════════════════════════════════
[0000]  INFO Service: SpartaHelloWorld                          LinkFlags= Option=provision UTC=2018-05-25T04:36:50Z
[0000]  INFO ════════════════════════════════════════════════
[0000]  INFO Using `git` SHA for StampedBuildID                 Command=git rev-parse HEAD SHA=7ee3e1bc52f15c4a636e05061eaec7b748db22a9
[0000]  INFO Provisioning service                               BuildID=7ee3e1bc52f15c4a636e05061eaec7b748db22a9 CodePipelineTrigger= InPlaceUpdates=false NOOP=false Tags=
[0000]  INFO Verifying IAM Lambda execution roles
[0000]  INFO IAM roles verified                                 Count=1
[0000]  INFO Checking S3 versioning                             Bucket=MY_S3_BUCKET VersioningEnabled=true
[0000]  INFO Checking S3 region                                 Bucket=MY_S3_BUCKET Region=us-west-2
[0000]  INFO Running `go generate`
[0000]  INFO Compiling binary                                   Name=Sparta.lambda.amd64
[0001]  INFO Creating code ZIP archive for upload               TempName=./.sparta/SpartaHelloWorld-code.zip
[0001]  INFO Lambda code archive size                           Size=13 MB
[0001]  INFO Uploading local file to S3                         Bucket=MY_S3_BUCKET Key=SpartaHelloWorld/SpartaHelloWorld-code.zip Path=./.sparta/SpartaHelloWorld-code.zip Size=13 MB
[0011]  INFO Uploading local file to S3                         Bucket=MY_S3_BUCKET Key=SpartaHelloWorld/SpartaHelloWorld-cftemplate.json Path=./.sparta/SpartaHelloWorld-cftemplate.json Size=2.2 kB
[0011]  INFO Creating stack                                     StackID=arn:aws:cloudformation:us-west-2:123412341234:stack/SpartaHelloWorld/44b426d0-5fd5-11e8-90cd-503f20f2ad82
[0039]  INFO CloudFormation Metrics ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
[0039]  INFO     Operation duration                             Duration=24.49s Resource=SpartaHelloWorld Type=AWS::CloudFormation::Stack
[0039]  INFO     Operation duration                             Duration=15.02s Resource=IAMRolebc3b888fab1664f42799785a6d9a3bb76ea63798 Type=AWS::IAM::Role
[0039]  INFO     Operation duration                             Duration=2.90s Resource=HelloworldtestLambdaa4a9e95c84255c65c284ce95dd7d3c45776c1a68 Type=AWS::Lambda::Function
[0039]  INFO Stack provisioned                                  CreationTime=2018-05-25 04:37:02.099 +0000 UTC StackId=arn:aws:cloudformation:us-west-2:123412341234:stack/SpartaHelloWorld/44b426d0-5fd5-11e8-90cd-503f20f2ad82 StackName=SpartaHelloWorld
[0039]  INFO ════════════════════════════════════════════════
[0039]  INFO SpartaHelloWorld Summary
[0039]  INFO ════════════════════════════════════════════════
[0039]  INFO Verifying IAM roles                                Duration (s)=0
[0039]  INFO Verifying AWS preconditions                        Duration (s)=0
[0039]  INFO Creating code bundle                               Duration (s)=1
[0039]  INFO Uploading code                                     Duration (s)=10
[0039]  INFO Ensuring CloudFormation stack                      Duration (s)=28
[0039]  INFO Total elapsed time                                 Duration (s)=39

3. Invoke 

Console GUI



Use a go monorepo to define and your microservice’s:

  • Application logic
  • AWS infrastructure
  • Operational metrics
  • Alert conditions
  • Security policies

Complete AWS Ecosystem

Sparta enables your lambda-based service to seamlessly integrate with the entire set of AWS lambda event sourcessuch as:

  • DynamoDB
  • S3
  • Kinesis
  • SNS
  • SES
  • CloudWatch Events
  • CloudWatch Logs

Additionally, your service may provision any other CloudFormation supported resource and even your own CustomResources.


Define IAM Roles with limited privileges to minimize your service’s attack surface. Both string literal and ARN expressions are supported in order to reference dynamically created resources. Sparta treats POLA and #SecOps as first-class goals.


A service may provision dynamic AWS infrastructure, and discover, at lambda execution time, the dependent resources’ AWS-assigned outputs (Ref & Fn::Att). Eliminate hardcoded Magic ARNs from your codebase and move towards immutable infrastructure

API Gateway

Make your service HTTPS accessible by binding it to an API Gateway REST API during provisioning. As part of API Gateway creation, Sparta includes API Gateway Mapping Templateswith all request data, including user-defined whitelisted parameters, so that you can focus on your core application logic.

Static Sites

Include a CORS-enabled S3-backed site with your service. S3-backed sites include API Gateway discovery information for turnkey deployment.

Sparta Overview

Sparta relies on CloudFormation to deploy and update your application. For resources that CloudFormation does not yet support, it uses Lambda-backed Custom Resources so that all service updates support both update and rollback semantics. Sparta’s automatically generated CloudFormation resources use content-based logical IDs whenever possible to preserve service availability and minimize resource churn during updates.

Getting Started

To get started using Sparta, begin with the Overview.


  • Problems? Please open an issue in GitHub.

Eveyone Welcome


Courtesy of gophers



Get in touch via:

Other resources 

Leave a Reply

Your email address will not be published. Required fields are marked *