Skip to content

Instantly share code, notes, and snippets.

@crazyguitar
Last active August 19, 2018 14:20
Show Gist options
  • Save crazyguitar/8180e53d7be19254d90d9723c9b2dc3f to your computer and use it in GitHub Desktop.
Save crazyguitar/8180e53d7be19254d90d9723c9b2dc3f to your computer and use it in GitHub Desktop.
Go lambda

AWS Lambda (Go)

directory layout

.
├── event.json
├── main.go
└── template.yml

main.go

package main

import (
	"github.com/aws/aws-lambda-go/lambda"
)

func hello() (string, error) {
	return "Hello ƛ!", nil
}

func main() {
	// Make the handler available for Remote Procedure Call by AWS Lambda
	lambda.Start(hello)
}

template.yml

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31

Description: An example lambda which is written by Golang
Resources:
  ExampleAPI:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: go1.x
      Handler: main

Run

$ GOOS=linux GOARCH=amd64 go build -o main main.go
$ echo '{}' > event.json
$ sam local invoke -e event.js

Reference

  1. aws/aws-lambda-go
  2. cpliakas/aws-sam-golang-example
  3. Lambda Function Handler (Go)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment