2017-05-28 64 views
0

我试图让每个调用lambda来记录开单时间,以跟踪使用lambda的开销。如何使用API​​网关获取AWS Lambda的LogResult?

当你调用与SDK或CLI拉姆达,你可以很容易地仅仅通过增加参数LogType: tail

然后你得到LogResult作为回应,在这里你可以提取计费时间的一部分得到LogResult。

现在,当我们通过API网关调用lambda时,我试图做类似的事情。

如何在这种情况下获得LogR​​esult和BilledDuration?

回答

0

在API网关中,您必须遵循API参考以使用“AWS服务”集成类型构建原始HTTP请求。

这里是an example for setting a different invocation parameter X-Amz-Invocation-Type,其中包括CLI调用来创建集成,也是一个招摇的例子。

在您的情况下,X-Amz-Log-Type的配置方式与名为integration.request.header.X-Amz-Log-Type的参数的配置方式相同。

{ 
    "swagger": "2.0", 
    "info": { 
    "version": "2016-02-11T22:00:31Z", 
    "title": "LambdaAsync" 
    }, 
    "host": "<placeholder>", 
    "basePath": "<placeholder>", 
    "schemes": [ 
    "https" 
    ], 
    "paths": { 
    "/": { 
     "get": { 
     "produces": [ 
      "application/json" 
     ], 
     "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-Log-Type": "'tail'" 
      }, 
      "type": "aws" 
     } 
     } 
    } 
    }, 
    "definitions": { 
    "Empty": { 
     "type": "object", 
     "title": "Empty Schema" 
    } 
    } 
} 
相关问题