首先,有人可能会说这个问题与HTTP request body not getting to AWS lambda function via AWS API Gateway或Getting json body in aws Lambda via API gateway非常相似
但是,这些问题都没有解决使用 Golang 的问题,我遇到的问题是找到event与 Node.js 文档中随处使用的参数等效的参数。
这是我的 Lambda 函数:
package main
import (
"context"
"encoding/json"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"
"log"
)
type MyReturn struct {
Response string `json:"response"`
}
type APIGWResponse struct {
IsBase64Encoded bool `json:"isBase64Encoded"`
StatusCode int `json:"statusCode"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
}
func handle(ctx context.Context, name MyReturn) (APIGWResponse, error) {
log.Print("Called by …Run Code Online (Sandbox Code Playgroud)