无法通过API网关POST请求在异步模式下执行Lambda

时间:2016-11-12 15:48:36

标签: amazon-web-services aws-lambda aws-api-gateway

为什么目前没有办法通过Gateway API在异步模式下执行AWS Lambda而不涉及调用invoke()方法的中间Lambda?

即使我添加这样的集成:

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'"
    }
)

它仍然同步执行...... 是否存在某些平台限制?

1 个答案:

答案 0 :(得分:0)

我有一个示例Swagger文档,您可以将调用类型切换为Lambda函数。我猜你已经有了如何映射头来触发不同的调用类型,但我想你可能会忘记部署API。

扬鞭

{
  "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"
    }
  }
}