Unable to execute Lambda in Async mode via API Gateway POST request

扶醉桌前 提交于 2019-12-14 03:53:47

问题


Why currently there no way to execute AWS Lambda in asynchronous mode via Gateway API without involving intermediary Lambda just for calling invoke() method?

Even if i add integration like this:

r = client.put_integration(
    restApiId=rest_api_id,
    resourceId=resource_id,
    httpMethod='POST',
    type='AWS',
    integrationHttpMethod='POST',
    uri=uri,
    requestParameters={
        'integration.request.header.X-Amz-Invocation-Type': "'Event'",
        'integration.request.header.Invocation-Type': "'Event'"
    }
)

It still executed synchronously... Are there some platform limitation or so?


回答1:


I have an example Swagger document which you can switch invocation type to Lambda function. I guess you already got how to map the header to trigger the different invocation types, but I think you might forget to deploy the API.

Swagger

{
  "swagger": "2.0",
  "info": {
    "version": "2016-02-11T22:00:31Z",
    "title": "LambdaAsync"
  },
  "host": "<placeholder>",
  "basePath": "<placeholder>",
  "schemes": [
    "https"
  ],
  "paths": {
    "/": {
      "get": {
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "X-Amz-Invocation-Type",
            "in": "header",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "schema": {
              "$ref": "#/definitions/Empty"
            }
          }
        },
        "x-amazon-apigateway-integration": {
          "passthroughBehavior": "when_no_match",
          "httpMethod": "POST",
          "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:<account>:function:<function_name>/invocations?Qualifier=$LATEST",
          "responses": {
            "default": {
              "statusCode": "200"
            }
          },
          "requestParameters": {
            "integration.request.header.X-Amz-Invocation-Type": "method.request.header.X-Amz-Invocation-Type"
          },
          "type": "aws"
        }
      }
    }
  },
  "definitions": {
    "Empty": {
      "type": "object",
      "title": "Empty Schema"
    }
  }
}


来源:https://stackoverflow.com/questions/40564597/unable-to-execute-lambda-in-async-mode-via-api-gateway-post-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!