简体   繁体   English

lambda 层是否与 Go 兼容?

[英]Is lambda layers compatible with Go?

Is it possible to use a Golang lambda with the new lambda layers feature from AWS?是否可以将 Golang lambda 与 AWS 的新 lambda 层功能一起使用?

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.我一直在尝试找到一种解决方案来使用我的 Lambda function 编写的 Go 中的层,但我无法这样做。 I got it working with python lambda though.我让它与 python lambda 一起工作。 I feel like since the Go code is a compiled binary, it's not possible to use a layer import during runtime.我觉得由于 Go 代码是编译后的二进制文件,因此在运行时无法使用图层导入。 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?有谁知道或有任何使用 Golang 的 Lambda 层的例子?

Is it possible to use a Golang lambda with the new lambda layers feature from AWS?是否可以将Golang Lambda与AWS的新Lambda图层功能一起使用?

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.我一直在尝试找到一种解决方案,以将层与用Go编写的Lambda函数一起使用,但是我无法做到这一点。 I got it working with python lambda though.我让它与python lambda一起工作。 I feel like since the Go code is a compiled binary, it's not possible to use a layer import during runtime.我觉得因为Go代码是编译的二进制文件,所以在运行时无法使用图层导入。 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?有谁知道或使用Golang的Lambda图层周围有任何示例吗?

Is it possible to use a Golang lambda with the new lambda layers feature from AWS?是否可以将Golang Lambda与AWS的新Lambda图层功能一起使用?

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.我一直在尝试找到一种解决方案,以将层与用Go编写的Lambda函数一起使用,但是我无法做到这一点。 I got it working with python lambda though.我让它与python lambda一起工作。 I feel like since the Go code is a compiled binary, it's not possible to use a layer import during runtime.我觉得因为Go代码是编译的二进制文件,所以在运行时无法使用图层导入。 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?有谁知道或使用Golang的Lambda图层周围有任何示例吗?

Unfortunately, in 2022, this is still a problem.不幸的是,在 2022 年,这仍然是一个问题。

Yes, you could build a plugin and create a layer, inject it into your lambda, but CGO_ENABLED is a deal-breaker.是的,您可以构建一个插件并创建一个层,将其注入您的 lambda,但CGO_ENABLED是一个交易破坏者。

Basically, your lambda requires CGO_ENABLED=0 during the build step.基本上,您的 lambda 在构建步骤中需要CGO_ENABLED=0 (eg. GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go ) (例如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但是,在禁用 CGO 的情况下,在 lambda 中使用“插件”会导致错误 - 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.据我所知,在本地,当 CGO 两次都启用时 - 即在构建插件和 go 模块时,导入插件按预期工作。 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.但是,在 AWS 中,为了让您的 lambda 工作,您需要在构建期间禁用 CGO,这意味着使用插件是脱离上下文的。

Discussion here - https://github.com/golang/go/issues/19569在这里讨论 - https://github.com/golang/go/issues/19569

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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