我在 VSCode 的 PowerShell 中完成了以下操作:
PS D:\Project Resume> set GOOS=linux
PS D:\Project Resume> set GOARCH=amd64
PS D:\Project Resume> set CGO_ENABLED=0
PS D:\Project Resume> cd .\dist\events\
PS D:\Project Resume\dist\events> go build -o main main.go
PS D:\Project Resume\dist\events> ~\Go\Bin\build-lambda-zip.exe -o main.zip main
2020/11/14 14:05:13 wrote main.zip
这似乎可以很好地压缩文件,我也在 Lambda 控制台中将处理程序更改为“main”。但是,我仍然得到这个:
START RequestId: 42d5f7d6-3c9d-457d-ab2f-5030b39a5bce Version: $LATEST
fork/exec /var/task/main: exec format error: PathError
null
END RequestId: 42d5f7d6-3c9d-457d-ab2f-5030b39a5bce
REPORT RequestId: 42d5f7d6-3c9d-457d-ab2f-5030b39a5bce Duration: 0.43 ms Billed Duration: 100 ms Memory Size: 512 MB Max Memory Used: 24 MB Init Duration: 2.84 ms
如果这很重要,这是我的代码(我按照 YouTube 上的教程,使用“main.go”作为文件名):
//Lambda Function Go Code
package main
import (
"errors"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func main() {
lambda.Start(HandleRequest)
}
//HandleRequest the request handler for our lambda stuff
func HandleRequest(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
if request.HTTPMethod == "POST" {
var stringResponse string = "Success :)"
APIResponse := events.APIGatewayProxyResponse{Body: stringResponse, StatusCode: 200}
return APIResponse, nil
}
err := errors.New("Method Not Allowed")
APIResponse := events.APIGatewayProxyResponse{Body: "Method Not OK", StatusCode: 502}
return APIResponse, err
}
出于好奇,我决定也检查 zip 文件的权限。这可能与它有关,可能吗???
慕森卡
慕村9548890
相关分类