Posting from AWS-API Gateway to Lambda

前端 未结 3 870
遇见更好的自我
遇见更好的自我 2020-12-29 11:19

I have a simple C# Aws Lambda function which succeeds to a test from the Lambda console test but fails with a 502 (Bad Gateway) if called from the API Gateway (which i gener

3条回答
  •  再見小時候
    2020-12-29 11:38

    When using Lambda Proxy Integration in API Gateway, the first parameter to your FunctionHandler is not the body of your POST, but is another API Gateway-created object, which let's call LambdaRequest. Try these changes to your sample code. Add:

    public class LambdaRequest
    {
       public string body { get; set; }
    }
    

    Change your handler prototype to:

    public LambdaResponse FunctionHandler(LambdaRequest req, ILambdaContext context)
    

    And inside FunctionHandler add:

    ZipRequest input = JsonConvert.DeserializeObject(req.Body);
    

    The full LambdaRequest object is documented under Input Format of a Lambda Function for Proxy Integration in the AWS docs, and contains HTTP headers, the HTTP method, the query string, the body, and a few other things.

提交回复
热议问题