背景
我正在使用Go开发AWS Lambda函数,其中一个依赖项是gopkg.in/h2non/bimg.v1
,它有一个依赖项:libvips 7.42+或8+(推荐8.4+)。
问题
问题在于,在我的本地计算机上Lambda处理程序可以工作,但是当我部署它时,出现了以下错误:
START RequestId: b4becbd1-3fca-4aed-9574-8df0e3d13c9e Version: $LATEST
/var/task/main: error while loading shared libraries: libvips.so.42: cannot open shared object file: No such file or directory
END RequestId: b4becbd1-3fca-4aed-9574-8df0e3d13c9e
REPORT RequestId: b4becbd1-3fca-4aed-9574-8df0e3d13c9e Duration: 42.36 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 12 MB
RequestId: b4becbd1-3fca-4aed-9574-8df0e3d13c9e Process exited before completing request
我的构建命令是:
GOOS=linux GOARCH=amd64 go build -o main main.go
我的尝试
我尝试启用c-shared
选项来构建它:
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -o main main.go
但是也遇到了一个错误,不过是另一种错误;
START RequestId: 9b90df21-1025-463b-89b1-1a4ee31f295c Version: $LATEST
fork/exec /var/task/main: permission denied: PathError
null
END RequestId: 9b90df21-1025-463b-89b1-1a4ee31f295c
REPORT RequestId: 9b90df21-1025-463b-89b1-1a4ee31f295c Duration: 0.77 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 30 MB Init Duration: 1.84 ms
我有两个选项(?):
- 使用完全基于Go语言的库进行重写
- 将libvips库打包到Go二进制文件中生成一个库。