以下是https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html的golang
示例lambda函数:
$ cat ./foo.go
package main
import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/lambda"
)
type MyEvent struct {
Name string `json:"name"`
}
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
return fmt.Sprintf("Hello %s!", name.Name ), nil
}
func main() {
lambda.Start(HandleRequest)
}
我相信我正确地遵循了创建部署程序包的步骤:
$ GOOS=linux go build foo.go
$ zip foo.zip foo
adding: foo (deflated 49%)
$
上面的lambda函数或部署包有什么问题?如果没有,为什么lambda create-function会失败,而无法找到处理程序脚本?
$ aws --profile jack --endpoint-url http://localhost:4574 lambda create-function --function-name foo --runtime go1.x --zip-file fileb://foo.zip --handler main --role arn:aws:iam::000000000000:role/lambda-role
An error occurred (ValidationError) when calling the CreateFunction operation: Unable to find handler script (/tmp/localstack/zipfile.07e4ae91/main) in Lambda archive. Config for local mount, docker, remote: "False", "True", "True"
$
最佳答案
请查看以下github问题和PR:
可能需要一些特殊步骤才能启用/使用localstack中的go。
关于amazon-web-services - 为什么在此AWS Lambda部署包中找不到处理程序脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61704264/