Is it possible to use a Golang lambda with the new lambda layers feature from AWS?
I have been trying to find a solution to use layers with my Lambda function written in Go, but I have not been able to do so. I got it working with python lambda though. I feel like since the Go code is a compiled binary, it's not possible to use a layer import during runtime. If I have the code for the layer locally, the import gets compiled into the binary as well which defeats the purpose of using a layer.
Does anyone know or have any examples around of Lambda Layers using Golang?
Go dependencies are inside the compiled binary, thus you can't/don't need to use layers. The problem is solved at a language level. It doesn't have anything to do with the fact that it is compiled, C and C++ binaries still have dependencies.
Actually it is possible to provide a Go layer with a pre-compiled plugin however there are so many restrictions that it isn't really useful:
In case of AWS Lambda Layers the last two points mentioned above make Go layers pretty useless. Since app code needs to import a shared package anyway why not import the actual package that would reside in the Go layer?
If I get this right the Go plugin system is meant to be used to provide pluggable implementations compiled and deployed together with the main application. It's not designed to be used by third parties to deliver custom application plugins.
The bottom line is: you can use Go + AWS Lambda Layers if you really want to however in practice it is not worth the effort in my opinion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With