Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform - How to enable API Gateway execution logging?

Question

How to setup API Gateway stage level execution logging with Terraform? Is it not supported yet?

Background

API Gateway stage editor has the execution logging configurations. However, it seems there is no parameter to set them in aws_api_gateway_stage although it has access loggging configuration parameters.

Wondering if there are another resources to use or simply those parameters have not been implemented.

enter image description here

like image 514
mon Avatar asked Sep 03 '18 21:09

mon


People also ask

How do I enable execution logs 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 find the API gateway execution log?

Open the CloudWatch console at https://console.amazonaws.cn/cloudwatch/ . In the navigation pane, choose Logs groups. Under the Log Groups table, choose a log group of the API-Gateway-Execution-Logs_{rest-api-id}/{stage-name} name.


1 Answers

You have to use aws_api_gateway_method_settings ...

resource "aws_api_gateway_method_settings" "YOUR_settings" {
  rest_api_id = "${aws_api_gateway_rest_api.YOUR.id}"
  stage_name  = "${aws_api_gateway_stage.YOUR.stage_name}"
  method_path = "*/*"
  settings {
    logging_level = "INFO"
    data_trace_enabled = true
    metrics_enabled = true
  }
}

the CloudWatch LogGroup should look like API-Gateway-Execution-Logs_{YOU_API_ID}/{YOU_STAGENAME}

... maybe you have to setup all the IAM role stuff ...

like image 138
dasrick Avatar answered Oct 25 '22 16:10

dasrick