Go Binary Optimiztion

Hello,

I use several Go Lambda functions that I compile as part of the install script and place the binaries in the functions folder. This worked for us for quite some time building the binaries with this command: go build -o functions/$bname -v $f/…; where $f is folder that stores Go code and $bname is name of file being compiled

We decided to optimize the binary by changing build command to: GOOS=linux GOARCH=amd64 go build -ldflags ‘-s -w’ -o functions/$bname -v $f/…;

The first part makes sure the binary is compiled for right environment for Lambda, and the ldflags make the binary smaller. This compiles fine in Netlify, and even indicates that all the functions have been uploaded however when I go to the functions tab and select the relevant branch, there are no Lambda Functions.

Is there a reason specifying the architecture and including the ldflags has made my Go binaries unusable for Netlify Functions?

Kind Regards

I’m not a great GO developer but I have seen people deploy GO functions with the GOOS set to linux and with the -ldflags flag. However, I’ve not see anyone mention setting the GOARCH. Could you try removing that (so it’s not specifically build for just x86_64) and see if that helps? Just a SWAG (scientific wild-a** guess) but hopefully helps. :laughing:

Thanks for reply. After trial and error it appears that removing the -s ldflag did the trick. No idea why

1 Like