【问题标题】:API Gateway Logging - Proxy Lambda - Request PathAPI 网关日志记录 - 代理 Lambda - 请求路径
【发布时间】:2019-09-06 11:54:02
【问题描述】:

我正在尝试将我的 API Gateway 日志推送到 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

【问题讨论】:

  • 如果您使用 Lambda 代理集成而不是自定义地图,则可以将其作为事件对象中的“路径”获取。

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


【解决方案1】:

原来我应该使用它作为我的 API 日志配置;

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

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 2019-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 2020-07-10
    • 1970-01-01
    相关资源
    最近更新 更多