API网关日志记录 - 代理Lambda - 请求路径

问题描述 投票:0回答:1

我正在尝试将我的API网关日志推送到Elasticsearch。我有这个工作,除了一个恼人的缺陷。我似乎无法获得原始资源路径,因为我正在使用代理lambda函数。我将API日志记录格式设置如下:

{
    "requestId": "$context.requestId",
    "ip": "$context.identity.sourceIp",
    "caller": "$context.identity.caller",
    "user": "$context.identity.user",
    "requestTime": "$context.requestTime",
    "httpMethod": "$context.httpMethod",
    "resourcePath": "$context.resourcePath",
    "status": "$context.status",
    "protocol": "$context.protocol",
    "responseLength": "$context.responseLength"
}

哪个给我以下内容;

{
    "requestId": "xxxxxxxxxxxxxx",
    "ip": "xxx.xxx.xxx.xxx",
    "caller": "-",
    "user": "-",
    "requestTime": "16/Apr/2019:11:03:49 +0000",
    "httpMethod": "GET",
    "resourcePath": "/{proxy+}",
    "status": "304",
    "protocol": "HTTP/1.1",
    "responseLength": "0"
}

如何获得实际的资源路径而不是/{proxy+}?文件似乎没有说清楚;

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#context-variable-reference?cmpid=docs_apigateway_console

amazon-web-services aws-api-gateway amazon-cloudwatch api-gateway aws-cloudwatch
1个回答
0
投票

事实证明我应该使用它作为我的API Logging配置;

{
    "requestId": "$context.requestId",
    "ip": "$context.identity.sourceIp",
    "caller": "$context.identity.caller",
    "user": "$context.identity.user",
    "requestTime": "$context.requestTime",
    "httpMethod": "$context.httpMethod",
    "resourcePath": "$context.path",
    "status": "$context.status",
    "protocol": "$context.protocol",
    "responseLength": "$context.responseLength"
}
© www.soinside.com 2019 - 2024. All rights reserved.