gpt4 book ai didi

exec format error in go aws-lambda with terraform(使用terraform执行AWS-lambda时出现EXEC格式错误)

转载 作者:bug小助手 更新时间:2023-10-25 14:35:47 30 4
gpt4 key购买 nike



I am actually facing a very rare issue in golang lambda invocation using terraform. So basically i am deploying all my resources using terraform like lambda, api gateway with golang. issue is when i deploy my golang lambda binary .zip file to lambda using terraform upon checking request with route it returns exec format error. all the code of terraform is fine and formating as i tested simple js lambda function it works fine. i guess its an issue with binary architecture but i am using same binary arch as of lambda using on aws. i also use provide.al2 same issue with exec format error if anyone can help.

实际上,我在使用terraform进行Golang lambda调用时遇到了一个非常罕见的问题。因此,基本上我是使用lambda这样的平台部署我的所有资源,也就是使用Golang的API网关。问题是,当我使用terraform将我的Golang lambda二进制.zip文件部署到lambda时,在使用ROUTE检查请求时,它返回EXEC格式错误。所有terraform的代码都很好,我测试了简单的js lambda函数,它工作得很好。我想这是二进制架构的问题,但我使用的是与AWS上使用的lambda相同的二进制拱门。如果有人能帮忙的话,我还会用到同样的exec格式错误问题Provide.al2。


some info for debugging

一些可供调试的信息


1- dir structure

一维结构


- infra
-- helloGO
-- main.go
-- main // binary file
-- terraform
-- main.tf
-- hello.zip // with main binary file


2- terraform lambda function resource

2-terraform lambda函数资源


resource "aws_lambda_function" "hello" {
function_name = "hello"
filename = "../hello.zip" // taking filename from root ./hello.zip

runtime = "go1.x" # nodejs16.x go1.x
handler = "main" # function.handler
role = aws_iam_role.hello_lambda_exec.arn
timeout = 3
}


3- build command

3-构建命令


buildGO: cleanGO
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 cd ./helloGo/ && go build -o ./ main.go
cd ./helloGo/ && chmod +x main
cd ./helloGo/ && zip ../hello.zip main

This creates build file main and package that to root as main.zip for lambda terraform file to use.
(amd64 is executable of x86_64)

这将创建构建文件main,并将其打包为要使用的lambda terraform文件的根目录为main.zip。(AMD64是x86_64的可执行文件)


i tried provided solutions like build with amd64 but dont know it lambda invocation go says binary not executable with this executable seems like

我尝试了提供的解决方案,如使用AMD64构建,但不知道它的lambda调用Go说二进制不可执行的这个可执行文件看起来像


更多回答
优秀答案推荐


i guess its an issue with binary architecture but i am using same binary arch as of lambda using on aws



You've got the right environment settings but you're setting them for the wrong command.

您获得了正确的环境设置,但您为错误的命令设置了它们。


GOOS=linux GOARCH=amd64 CGO_ENABLED=0 cd ./helloGo/ && go build -o ./ main.go

This line sets GOOS, GOARCH, and CGO_ENABLED for the cd command, not for go build.

该行为cd命令设置GOOS、GOARCH和CGO_ENABLED,而不是GO BUILD。


Try this:

试试这个:


cd ./helloGo/ && GOOS=linux GOARCH=amd64 CGO_ENABLED=0  go build -o ./ main.go

更多回答

Thanks for the help i actually missed that part also i was not using hash to generate new s3 bucket but real problem was that you mentioned thanks a ton

谢谢你的帮助,我实际上错过了这一部分,而且我没有使用散列来生成新的S3存储桶,但真正的问题是你提到了很多谢谢

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com