1
votes

I am trying to push my API Gateway logs into Elasticsearch. I have this working with the exception of one annoying flaw. I can't seem to get the original resource path as I am using a proxy lambda function. I set my API logging format up as follows;

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

Which give me the following out;

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

How do I get the actual resource path instead of /{proxy+}? The documentation doesn't seem to make it clear;

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

1
If you use Lambda Proxy Integration instead of your custom map, you can get it as 'path' inside the event object. - Shuvojit

1 Answers

3
votes

Turns out I should have used this as my API Logging config;

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