2
votes

If I set a header X-Amz-Invocation-Type: 'Event', the call is done asynchronously but as the Amazon documentation states (https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-simple-proxy-for-lambda-output-format), when one uses Proxy Lambda Integration, the lambda function must return a well formatted response of this kind:

callback(null, {"statusCode": 200, "body": "results"})

As the lambda function is called asynchronously, the API Gateway never get an answer and then return a 502 Bad Gateway error instead of a 200 OK status.

Below an extract of the swagger configuration:

"/myFunc": {
  "post": {
    "parameters": [
      {
        "name": "myparam",
        "in": "query",
        "required": true,
        "type": "string"
      }
    ],
    "responses": {
      "200": {
        "description": "200 response"
      }
    },
    "x-amazon-apigateway-request-validator": "Validate query string parameters and headers",
    "x-amazon-apigateway-integration": {
      "responses": {
        "default": {
          "statusCode": "200"
        }
      },
      "uri": "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:idAccount:function:myFunc/invocations",
      "passthroughBehavior": "when_no_match",
      "httpMethod": "POST",
      "type": "aws_proxy",
      "requestParameters": {
        "integration.request.header.X-Amz-Invocation-Type": "'Event'"
      }
    }
  }
}

Is there a way to have it worked?

1
Lambda, itself, should return a well-formed response to an asynchronous invocation... at least, that's what this seems to indicate.Michael - sqlbot
They're not using the Lambda Proxy Integration in this tutorial... It's working if I don't use the Lambda Proxy Integration but I have to use a body template to pass through the request params and stage variablesAlexandre
@Alexandre i'm just facing the same issue. Did you manage to fix that?Pawel
No, instead I use the body template as explained in my previous comment... I hope Amazon will fix this, maybe this should be reported elsewhere?Alexandre

1 Answers

0
votes

You can setup a custom lambda integration (without proxy flag). You will need to configure the mapping templates to transform the request/response to your desired format.

http://docs.aws.amazon.com/apigateway/latest/developerguide/getting-started-lambda-non-proxy-integration.html#getting-started-new-lambda