Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway $input variable in CloudWatch

Is it possible to log the $input variable (body variables) of a request to API Gateway from CloudWatch?

The Log format of the Custom Access Logging doesn't seem to accept $input.body or any of the other $input functions:

{"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", "body": "$input.body", params: "$input.params()"}
like image 899
leeodelion Avatar asked Mar 07 '18 02:03

leeodelion


People also ask

How do I enable CloudWatch Logs for APIS in API Gateway?

On the Logs/Tracing tab, under CloudWatch Settings, do the following to turn on execution logging: Choose the Enable CloudWatch Logs check box. For Log level, choose INFO to generate execution logs for all requests. Or, choose ERROR to generate execution logs only for requests to your API that result in an error.

How do I use stage variables in API Gateway?

To declare stage variables using the API Gateway consoleCreate an API, create a GET method on the API's root resource, if you have not already done so. Set the HTTP Endpoint URL value as " http://${stageVariables.url} ", and then choose Save. Choose Deploy API. Choose New Stage and enter " beta " for Stage name.

How do I access CloudWatch Logs API Gateway?

To view API Gateway logs, log in to your AWS Console and select CloudWatch from the list of services. Select Logs from the left panel. Select the log group prefixed with API-Gateway-Execution-Logs_ followed by the API Gateway id. You should see 300 log streams ordered by the last event time.


1 Answers

Short answer: No

You can use $context variables in the access logging as documented in

https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-logging.html.

Other variables including $input are not supported. If you want to log the request/response header values, you can use execution logging with enabling 'Log full requests/responses data'.

like image 103
Cesar Canassa Avatar answered Sep 29 '22 15:09

Cesar Canassa