我正在使用基本示例在 Ubuntu 上构建 lambda。
它构建时没有任何错误,但如果我在 aws 上上传并测试它,则会崩溃:
{
"errorMessage": "RequestId: 7f4d0aca-125c-4032-98dd-9ff387e5252b Error: Runtime exited with error: exit status 1",
"errorType": "Runtime.ExitError"
}
日志输出为:
START
RequestId: 7f4d0aca-125c-4032-98dd-9ff387e5252b
Version: $LATEST.~.jwtauthorizeraws.jwtauthorizerawsapplication: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./~.jwtauthorizerawsapplication)
END
RequestId: 7f4d0aca-125c-4032-98dd-9ff387e5252b
REPORT
RequestId: 7f4d0aca-125c-4032-98dd-9ff387e5252b
Duration: 56.02 ms
Billed Duration: 57 ms
Memory Size: 128 MB
Max Memory Used: 7 MB
RequestId: 7f4d0aca-125c-4032-98dd-9ff387e5252b
Error: Runtime exited with error: exit status 1
Runtime.ExitError
我最近遇到了这个问题。
构建您的项目CGO_ENABLED=0
可能足以解决你的问题 https://github.com/aws/aws-lambda-go/issues/340:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
如果您正在使用sam
,有一个--use-container
然而,标志这可能不适用于 golang 项目 https://github.com/aws/aws-sam-cli/issues/3894
To make sam build
使用自定义构建命令,即运行go build
上面的命令,你可以设置BuildMethod
to makefile
并创建一个Makefile
目标名称为build-<YourFunctionName>
.
HealthCheckFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: makefile
Properties:
CodeUri: .
Handler: healthcheck
FunctionName: !Sub "healthcheck_${Env}"
Runtime: go1.x
Architectures:
- x86_64
Events:
...
然后Makefile
将有:
build-HealthCheckFunction:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o healthcheck lambda/healthcheck/healthcheck.go
mv healthcheck $(ARTIFACTS_DIR)
这里有更多关于我必须做什么才能在我的项目中解决这个问题的详细信息:https://www.gaunt.dev/blog/2022/glibc-error-with-aws-sam-and-go/ https://www.gaunt.dev/blog/2022/glibc-error-with-aws-sam-and-go/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)