简体   繁体   中英

Is lambda layers compatible with Go?

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?

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?

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?

Unfortunately, in 2022, this is still a problem.

Yes, you could build a plugin and create a layer, inject it into your lambda, but CGO_ENABLED is a deal-breaker.

Basically, your lambda requires CGO_ENABLED=0 during the build step. (eg. GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go )

However, with CGO disabled, using "plugin" in your lambda results in an error - plugin: not implemented

From what I can confirm, on local, when CGO is enabled both the times - ie while building plugin & the go module, importing plugin works as expected. However, in AWS, for your lambda to work you will need to disable CGO during the build which means, working with plugins is out of context.

Discussion here - https://github.com/golang/go/issues/19569

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM