"exec format error" from SAM Local with Golang on Mac

I was getting my hands dirty with AWS SAM Local and Golang based functions the other day (since golang function support was added in 0.2.7), and ran it to a basic - but cryptic - error that took me way too long to understand: fork/exec /var/task/main: exec format error

I wanted to put it here so I don't forget the cause (again). Here's the full request and error message output of aws-sam-local (or sam):

START RequestId: 3ace7e58-712c-1029-52d6-5ff93e3083d2 Version: $LATEST
END RequestId: 3ace7e58-712c-1029-52d6-5ff93e3083d2
REPORT RequestId: 3ace7e58-712c-1029-52d6-5ff93e3083d2  Duration: 5.78 ms       Billed Duration: 100 ms Memory Size: 128 MB     Max Memory Used: 6 MB
{
  "errorMessage": "fork/exec /var/task/main: exec format error",
  "errorType": "PathError"
}
2018/03/02 15:14:25 Function returned an invalid response (must include one of: body, headers or statusCode in the response object): unexpected end of JSON input

Remember to include GOOS=linux on Mac when building functions for AWS SAM Local!

GOOS=linux go build main.go

The local environment is still using Docker (specifically the docker-lambda containers provided by lambci) so the binaries are run in a Linux container, and must be compiled appropriately.