2017-05-28 63 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" 
    } 
    } 
} 
相關問題