2

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?

4
  • Lambda, itself, should return a well-formed response to an asynchronous invocation... at least, that's what this seems to indicate. Commented Aug 15, 2017 at 23:01
  • 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 variables Commented Aug 16, 2017 at 7:28
  • @Alexandre i'm just facing the same issue. Did you manage to fix that? Commented Sep 11, 2017 at 10:57
  • 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? Commented Sep 11, 2017 at 11:36

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.