如何使用API网关获取AWS Lambda的日志结果?
我试图每次调用lambda来记录计费的持续时间,以跟踪使用lambda的成本 使用SDK或CLI调用lambda时,只需添加参数如何使用API网关获取AWS Lambda的日志结果?,lambda,aws-lambda,aws-api-gateway,Lambda,Aws Lambda,Aws Api Gateway,我试图每次调用lambda来记录计费的持续时间,以跟踪使用lambda的成本 使用SDK或CLI调用lambda时,只需添加参数LogType:tail 然后,您将得到日志结果作为响应的一部分,您可以从中提取计费的持续时间 现在,当我们通过API网关调用lambda时,我也在尝试做类似的事情 在这种情况下,我如何获得日志结果和计费持续时间?在API网关中,您必须遵循API参考来构建具有“AWS服务”集成类型的原始HTTP请求 下面是一个包含创建集成的CLI调用的示例,以及一个招摇过市的示例 在您
LogType:tail
然后,您将得到日志结果作为响应的一部分,您可以从中提取计费的持续时间
现在,当我们通过API网关调用lambda时,我也在尝试做类似的事情
在这种情况下,我如何获得日志结果和计费持续时间?在API网关中,您必须遵循API参考来构建具有“AWS服务”集成类型的原始HTTP请求 下面是一个包含创建集成的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"
}
}
}
{
“招摇过市”:“2.0”,
“信息”:{
“版本”:“2016-02-11T22:00:31Z”,
“标题”:“lambdasync”
},
“主机”:“,
“基本路径”:“,
“计划”:[
“https”
],
“路径”:{
"/": {
“获取”:{
“生产”:[
“应用程序/json”
],
“答复”:{
"200": {
“说明”:“200响应”,
“模式”:{
$ref:“#/definitions/Empty”
}
}
},
“x-amazon-apigateway-integration”:{
“传递行为”:“当不匹配时”,
“httpMethod”:“POST”,
“uri”:“arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1::function:/invocations?限定符=$LATEST”,
“答复”:{
“默认值”:{
“状态代码”:“200”
}
},
“请求参数”:{
“integration.request.header.X-Amz-Log-Type”:“tail”
},
“类型”:“aws”
}
}
}
},
“定义”:{
“空”:{
“类型”:“对象”,
“标题”:“空架构”
}
}
}