我在 VSCode 的 PowerShell 中完成了以下操作:PS D:\Project Resume> set GOOS=linuxPS D:\Project Resume> set GOARCH=amd64PS D:\Project Resume> set CGO_ENABLED=0PS D:\Project Resume> cd .\dist\events\PS D:\Project Resume\dist\events> go build -o main main.goPS D:\Project Resume\dist\events> ~\Go\Bin\build-lambda-zip.exe -o main.zip main2020/11/14 14:05:13 wrote main.zip這似乎可以很好地壓縮文件,我也在 Lambda 控制臺中將處理程序更改為“main”。但是,我仍然得到這個:START RequestId: 42d5f7d6-3c9d-457d-ab2f-5030b39a5bce Version: $LATESTfork/exec /var/task/main: exec format error: PathErrornullEND RequestId: 42d5f7d6-3c9d-457d-ab2f-5030b39a5bceREPORT 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 Codepackage mainimport ( "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 stufffunc 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 文件的權限。這可能與它有關,可能嗎???
2 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
就我而言,我正在關注文檔,認為設置 GOOS env 變量的命令是這樣的:
set GOOS=linux
但是,根據以下文檔:
https://mcpmag.com/articles/2019/03/28/environment-variables-in-powershell.aspx?m=1
由于我在 PowerShell 中運行,我應該使用這個命令:
$env:GOOS = "linux"
正如許多文檔在其他地方所說,當您在 PowerShell 中使用以下內容時,無論是從 VSCode 還是在該 IDE 之外,您都會知道您已經正確設置了 env 變量:
go env
我希望這可以幫助某人在 Windows 中進行編譯。
- 2 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消