Skip to content

Commit 4608de3

Browse files
committed
Add a section on debugging the API Gateway to aws_lambda_api module.
1 parent 726f1cc commit 4608de3

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

aws_lambda_api/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,63 @@ aws lambda update-function-code --function-name my-prod-function-name --s3-bucke
193193

194194
...or some variation thereof. You get the idea.
195195

196+
## Debugging API Gateway
197+
198+
If something isn't working right with your API Gateway, set `api_gateway_logging_level = "INFO"`. Additionally, you need to add the following **global configuration** for your API Gateway:
199+
200+
```tf
201+
resource "aws_api_gateway_account" "this" {
202+
cloudwatch_role_arn = "${aws_iam_role.apigateway_cloudwatch_logging.arn}"
203+
}
204+
205+
resource "aws_iam_role" "apigateway_cloudwatch_logging" {
206+
name = "apigateway-cloudwatch-logging"
207+
208+
assume_role_policy = <<EOF
209+
{
210+
"Version": "2012-10-17",
211+
"Statement": [
212+
{
213+
"Effect": "Allow",
214+
"Principal": {
215+
"Service": "apigateway.amazonaws.com"
216+
},
217+
"Action": "sts:AssumeRole"
218+
}
219+
]
220+
}
221+
EOF
222+
}
223+
224+
resource "aws_iam_role_policy" "apigateway_cloudwatch_logging" {
225+
name = "apigateway-cloudwatch-logging"
226+
role = "${aws_iam_role.apigateway_cloudwatch_logging.id}"
227+
228+
policy = <<EOF
229+
{
230+
"Version": "2012-10-17",
231+
"Statement": [
232+
{
233+
"Effect": "Allow",
234+
"Action": [
235+
"logs:CreateLogGroup",
236+
"logs:CreateLogStream",
237+
"logs:DescribeLogGroups",
238+
"logs:DescribeLogStreams",
239+
"logs:PutLogEvents",
240+
"logs:GetLogEvents",
241+
"logs:FilterLogEvents"
242+
],
243+
"Resource": "*"
244+
}
245+
]
246+
}
247+
EOF
248+
}
249+
```
250+
251+
Otherwise API Gateway won't have permission to write logs to CloudWatch.
252+
196253
<!-- terraform-docs:begin -->
197254
## Inputs
198255

0 commit comments

Comments
 (0)