If you’re building locally then you need to make sure you are setting the proper compile targets since it’ll be executed in a lambda container on linux. If you build on mac, then you’ll get a mac binary by default. That means your local build command would have to be something like this:
GOOS=linux GOARCH=amd64 go build function_name.go
You can build it in our build environment during your build as well. I have a go function deploying in https://github.com/futuregerald/functions-react-mongo/blob/master/src/lambda/validate-user.go
I chain the build command in my package.json as an npm script, though it can be run directly as part of your build command. The build command can be found in that repo at https://github.com/futuregerald/functions-react-mongo/blob/master/package.json#L28:
"build:lambda": "netlify-lambda build src/lambda && go get ./src/lambda/... && go build -o lambda/validate-user ./src/lambda/validate-user.go"
The relevant part for building the go function is:
go build -o lambda/validate-user ./src/lambda/validate-user.go"
Note that you still need to make sure you have your
GO_IMPORT_PATH environment variable set. I have it in my netlify.toml: https://github.com/futuregerald/functions-react-mongo/blob/master/netlify.toml#L6