Home > OS >  How can I enable CloudWatch logging on an API Gateway v2 API via Terraform?
How can I enable CloudWatch logging on an API Gateway v2 API via Terraform?

Time:05-25

I would like to enable execution logging on an aws_apigatewayv2_api resource. I can simply click the below checkbox to do so.

Since I know it is possible via AWS GUI, what is the terraform equivalent?

I already have logging enabled on each individual integration lambda, but this checkbox stays unchecked.

enter image description here

CodePudding user response:

This setting is on the stage itself i.e. aws_apigatewayv2_stage under the default_route_settings argument.

To replicate the UI:

  • Enable CloudWatch Logs & Log level - these 2 options are combined in Terraform under logging_level. Logging is disabled by default as logging_level is set to OFF. To enable logging, you will need to simply specify the logging_level to any other supported value other than OFF, which has the effect of turning logging on & setting the level at the same time.

  • Log full message data - this is in Terraform under detailed_metrics_enabled.

This results in the below config:

resource "aws_apigatewayv2_stage" "example" {
  api_id = aws_apigatewayv2_api.example.id
  name   = "example-stage"
  default_route_settings {
    logging_level = "INFO"
    detailed_metrics_enabled = true
  }
}
  • Related