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()"}
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.
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.
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.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With