1

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. Commented Apr 16, 2019 at 11:34

1 Answer 1

3

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"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.