github.com/Foodji/aws-lambda-go@v1.20.2/README.md (about) 1 # AWS Lambda for Go 2 3 [![tests][1]][2] 4 [![build-lambda-zip][3]][4] 5 [![GoDoc][5]][6] 6 [![GoCard][7]][8] 7 [![codecov][9]][10] 8 9 [1]: https://github.com/aws/aws-lambda-go/workflows/tests/badge.svg 10 [2]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3Atests 11 [3]: https://github.com/aws/aws-lambda-go/workflows/go%20get%20build-lambda-zip/badge.svg 12 [4]: https://github.com/aws/aws-lambda-go/actions?query=workflow%3A%22go+get+build-lambda-zip%22 13 [5]: https://godoc.org/github.com/aws/aws-lambda-go?status.svg 14 [6]: https://godoc.org/github.com/aws/aws-lambda-go 15 [7]: https://goreportcard.com/badge/github.com/aws/aws-lambda-go 16 [8]: https://goreportcard.com/report/github.com/aws/aws-lambda-go 17 [9]: https://codecov.io/gh/aws/aws-lambda-go/branch/master/graph/badge.svg 18 [10]: https://codecov.io/gh/aws/aws-lambda-go 19 20 Libraries, samples, and tools to help Go developers develop AWS Lambda functions. 21 22 To learn more about writing AWS Lambda functions in Go, go to [the official documentation](https://docs.aws.amazon.com/lambda/latest/dg/go-programming-model.html) 23 24 # Getting Started 25 26 ``` Go 27 // main.go 28 package main 29 30 import ( 31 "github.com/aws/aws-lambda-go/lambda" 32 ) 33 34 func hello() (string, error) { 35 return "Hello ƛ!", nil 36 } 37 38 func main() { 39 // Make the handler available for Remote Procedure Call by AWS Lambda 40 lambda.Start(hello) 41 } 42 ``` 43 44 # Building your function 45 46 Preparing a binary to deploy to AWS Lambda requires that it is compiled for Linux and placed into a .zip file. 47 48 ## For developers on Linux and macOS 49 ``` shell 50 # Remember to build your handler executable for Linux! 51 GOOS=linux GOARCH=amd64 go build -o main main.go 52 zip main.zip main 53 ``` 54 55 ## For developers on Windows 56 57 Windows developers may have trouble producing a zip file that marks the binary as executable on Linux. To create a .zip that will work on AWS Lambda, the `build-lambda-zip` tool may be helpful. 58 59 Get the tool 60 ``` shell 61 set GO111MODULE=on 62 go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip 63 ``` 64 65 Use the tool from your `GOPATH`. If you have a default installation of Go, the tool will be in `%USERPROFILE%\Go\bin`. 66 67 in cmd.exe: 68 ``` bat 69 set GOOS=linux 70 set GOARCH=amd64 71 set CGO_ENABLED=0 72 go build -o main main.go 73 %USERPROFILE%\Go\bin\build-lambda-zip.exe -o main.zip main 74 ``` 75 76 in Powershell: 77 ``` posh 78 $env:GOOS = "linux" 79 $env:GOARCH = "amd64" 80 $env:CGO_ENABLED = "0" 81 go build -o main main.go 82 ~\Go\Bin\build-lambda-zip.exe -o main.zip main 83 ``` 84 # Deploying your functions 85 86 To deploy your function, refer to the official documentation for [deploying using the AWS CLI, AWS Cloudformation, and AWS SAM](https://docs.aws.amazon.com/lambda/latest/dg/deploying-lambda-apps.html). 87 88 # Event Integrations 89 90 The [event models](https://github.com/aws/aws-lambda-go/tree/master/events) can be used to model AWS event sources. The official documentation has [detailed walkthroughs](https://docs.aws.amazon.com/lambda/latest/dg/use-cases.html). 91