Main features

Describe Serverless templates as Go objects (structs), and then turn it into YAML.

Installation

As with other Go libraries, GoFormation can be installed with go get.

$ go get github.com/thepauleh/goserverless/serverless

Usage

Marshalling Serverless with Go structs, into YAML

Below is an example of building a CloudFormation template programmatically, then outputting the resulting JSON

packagemainimport("fmt""github.com/thepauleh/goserverless/serverless")funcmain(){// Create a new CloudFormation templatetemplate:=serverless.NewTemplate("myService")template.Service="myService"template.Provider=&serverless.Provider{Name:"aws",Runtime:"nodejs6.10",MemorySize:512,Timeout:10,VersionFunctions:false}// An example functiontemplate.Functions["users"]=&serverless.AWSServerlessFunction{Handler:"service.o",Name:"${self:provider.stage}-users",Description:"Description of what the lambda function does",Runtime:"go1.x",MemorySize:128,ReservedConcurrency:5,Timeout:30,Events:[]serverless.Events{serverless.HttpEvent{Path:"users/create",Method:"post",},},}y,err:=template.YAML()iferr!=nil{fmt.Printf("Failed to generate YAML: %s\n",err)}else{fmt.Printf("%s\n",string(y))}}

Would output the following YAML template:

service:myServiceprovider:name:awsruntime:nodejs6.10memorySize:512timeout:10versionFunctions:falsefunctions:users:handler:service.oname:${self:provider.stage}-usersdescription:Description of what the lambda function doesruntime:go1.xmemorySize:128timeout:30reservedConcurrency:5events:-http:path:users/createmethod:post

Want more Serverless?

Subscribe to our mailing list to receive an update when new items arrive!