所以我一直在探索Lambda容器图像
我有一个lambda函数如下
test.go:
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
fmt.Println("Request %s \n\n", request)
fmt.Println("Context %s \n\n", ctx)
name := request.QueryStringParameters["name"]
return events.APIGatewayProxyResponse{Body: fmt.Sprint("Hello %s", name), StatusCode: 200}, nil
}
func main() {
lambda.Start(handleRequest)
}我的码头档案:
FROM amazon/aws-lambda-go
COPY bin/test /var/task
CMD [ "test" ]我使用标记作为testing_go构建了上面的docker文件,并按如下方式运行它
docker run -p 8080:8080 testing_go并尝试按以下方式调用它
curl -X GET --url http://localhost:8080/2015-03-31/functions/function/invocations?name=JOHN --header 'Content-Type: application/json' --data '{}'我看到容器日志为上下文和请求的值显示了以下内容
Request %s
{ map[] map[] map[] map[] map[] map[] { { } map[] 0 } false}
Context %s
context.Background.WithDeadline(2020-12-23 03:07:06.186819041 +0000 UTC [325h22m17.998420615s]).WithValue(type *lambdacontext.key, val <not Stringer>).WithValue(type string, val )
map[]问题:
如果有人能帮我解决这个问题会很有帮助的。
编辑:在打破我的头一段时间后,我能够弄清楚它。答案是
curl -X GET --url http://localhost:8080/2015-1/functions/function/invocations --header 'Content-Type: application/json' --data '{"queryStringParameters": {"name": "john"}}'发布于 2020-12-10 06:35:33
在尝试了一堆内容之后,我发现如果我们想在本地调用lambda并将一个值作为查询字符串参数传递,我需要这样做:
curl -X GET --url http://localhost:8080/2015-1/functions/function/invocations --header 'Content-Type: application/json' --data '{"queryStringParameters": {"name": "john"}}'https://stackoverflow.com/questions/65223288
复制相似问题