API Gateway logging with Terraform

Edoardo Nosotti
RockedScience
Published in
4 min readMay 10, 2019

--

photo credits

A quick tutorial on how to enable CloudWatch logging for API Gateways on AWS in a Terraform plan.

For want of a log…

It’s hard to think of an HTTP server without access and error logs. Sure, API Gateway is a fully-managed service meant to take the hassle of handling the stack away from you, but there is still a lot of value in its logs:

  • troubleshooting: if you point your API Gateway to a Lambda function and don’t grant proper invocation permissions, the Lambda will not be invoked at all and logging will happen there, so the API Gateway logs are the only possible source of information for such errors
  • debugging: the full requests content can be dumped to the logs for inspection
  • profiling: detailed metrics can be logged as well and used to evaluate the performances your API services

…that plays hard to get

When you deploy your first API Gateway on AWS and try to properly set it up, enabling logging looks as easy as checking a couple of flags:

Figure #1 — An API Gateway deployment settings

--

--

Edoardo Nosotti
RockedScience

Certified Cybersecurity Analyst and Senior Cloud Solutions Architect. Passionate about IoT, AI, ML and automation.