AWS API Gateway Custom Authorizer log
Asked Answered
B

2

8

How do get logging from custom authorizer lambda function in API Gateway? I do not want to enable logging for API. I need logging from authorizer lambda function. I use a python lambda function and have prints in the code. I want to view the prints in Cloud Watch logs. But logs are not seen in cloud watch. I do not get errors either. What am I missing?
Lambda has execution role role/service-role/MyLambdaRole. This role has the policy to write to cloud watch.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "logs:CreateLogGroup",
            "Resource": "arn:aws:logs:us-east-1:123456:*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "arn:aws:logs:us-east-1:123456:log-group:MyCustomAuthorizer:*"
            ]
        }
    ]
}

I also tested by adding CloudWatchLogsFullAccess policy to role/service-role/MyLambdaRole role.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "logs:*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}
Brisesoleil answered 26/7, 2016 at 14:55 Comment(0)
B
3

I deleted the lambda function, IAM role, custom authorizer from API Gateway. Recreated all the above with the same settings and published the API. It started working and logging as expected. I do not know what was preventing earlier to log to cloud watch logs. Weird!!

Brisesoleil answered 26/7, 2016 at 16:20 Comment(3)
I'm getting this too. Recreation didn't help. Have you found the cause by any chance?Fevre
Same problem hereExorable
Same problem hereWeismannism
F
1

When I set up my authorizer, I set a Lambda Event payload for a custom header, and I had neglected to set that header in my browser session. According to the documentation at https://docs.aws.amazon.com/apigateway/latest/developerguide/configure-api-gateway-lambda-authorization-with-console.html, section 9b, the API Gateway will throw a 401 Unauthorized error without even executing the Lambda function. So that was the source of the problem.

Fong answered 22/6, 2022 at 11:8 Comment(1)
How does this relate to the question?Laryngitis

© 2022 - 2024 — McMap. All rights reserved.