第一個示例是沒有問題的代碼:你用這個做一個羊羔:package mainimport ( "github.com/aws/aws-lambda-go/lambda")func main() { lambda.Start(Handler)}func Handler(s interface{}) (interface{}, error) { return s, nil}當我轉到lambda的測試部分時,我用這個作為我的測試:{"id":"123"}并返回:{"id":"123"}然后,我使用這個作為 lambda GUI 中的測試:[{"id":"123"}]并返回:[{"id":"123"}]我把它放在一個API網關后面,并發送相同的字符串:curl https://69wisebmza.execute-api.us-east-1.amazonaws.com/default/simplestlambda -d '{"id":"123"}' --header "Content-Type: application/json"這將返回一個響應,其開頭為:{"id":"123"}所以這是有問題的代碼 - 唯一的變化是它接受并返回一段接口:package mainimport ( "github.com/aws/aws-lambda-go/lambda")func main() { lambda.Start(Handler)}func Handler(s []interface{}) ([]interface{}, error) { return s, nil}從 lambda GUI 測試控制臺中,我發送:[{"id":"123"}]并接收回:[{"id":"123"}]從同一個控制臺,我發送:{"id":"123"}并接收回此預期錯誤:{ "errorMessage": "json: cannot unmarshal object into Go value of type []interface {}", "errorType": "UnmarshalTypeError"}目前為止,一切都好。現在,我把它放在一個API網關后面,并執行以下操作:curl https://oz72tn566l.execute-api.us-east-1.amazonaws.com/default/simplestslice -d '[{"id":"123"}]' --header "Content-Type: application/json"我得到:{"message":"Internal Server Error"}日志顯示:json: cannot unmarshal object into Go value of type []interface {}: UnmarshalTypeErrornull所以我想知道為什么這可能不起作用?
如何通過 API 網關將 JSON 數組發布到 AWS Lambda?
慕的地6264312
2022-09-19 20:48:49