Skip to content

Instantly share code, notes, and snippets.

@djm
Last active July 1, 2024 15:27
Show Gist options
  • Save djm/15cf09b6b21c20332a602d3bca6b6d08 to your computer and use it in GitHub Desktop.
Save djm/15cf09b6b21c20332a602d3bca6b6d08 to your computer and use it in GitHub Desktop.
Fix for AWS API Gateway Custom Authorizer Error => AuthorizerConfigurationException (message: null)
Problem: you've created a Custom Authorizer Lambda and have hooked it up with Amazon AWS's API Gateway.
But now all of your responses return the following HTTP response with the "AuthorizerConfigurationException"
and your Cloudwatch logs for your Authorizer function are next to useless..
-----
HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Length: 16
Content-Type: application/json
Date: Mon, 03 Feb 2020 22:12:26 GMT
Via: 1.1 b9061e936b29505d1b542db7af99b46c.cloudfront.net (CloudFront)
X-Amz-Cf-Id: V_ATyX6PguLX2OKELQaw7HIwyvKcU_bXJm3rXGsCp31UCwILvA70EA==
X-Amz-Cf-Pop: LHR61-C2
X-Cache: Error from cloudfront
x-amz-apigw-id: HV0fpFt_oAMFimA=
x-amzn-ErrorType: AuthorizerConfigurationException
x-amzn-RequestId: d889cc44-cf79-404a-af1d-c8cc1f09d5bc
{
"message": null
}
Solution (or at least one possible one): Your code is generating a policy with an invalid context.
For example, in Python, your authorizer might return:
return {
"principalId": principal_id,
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{"Action": "execute-api:Invoke", "Effect": effect, "Resource": resource}
],
},
"context": {
"some_nested_data": {
"id": 3
},
"user_id": 4,
},
}
There are no valid keys in this example context.
The context _must_ abide by two rules:
1. All keys must be top level. No nested data.
2. All values must be strings, integers or booleans.
That means no setting nested JSON data to the context; and no making lists/arrays as the values.
When you get the data in your endpoint function, all the values will have been stringified.
Why? Absolutely fuck knows. Sorry, I can't help you there.
@heshamnaim
Copy link

Life saver!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment