I have a lambda authorizer that is written in Python.
I know that with the following access policy I can return 200/403 :
{
"principalId": "yyyyyyyy",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "execute-api:Invoke",
"Effect": "Deny",
"Resource": "*"
}
]
},
"context": {
"stringKey": "value",
"numberKey": "1",
"booleanKey": "true"
},
"usageIdentifierKey": "{api-key}"
}
I'm trying to return 401 error if the customer didn't send any token, therefore I'm raising an exception :
raise Exception("Unauthorized")
The problem with this solution is that the AWS lambda fails and then the execution is marked as a failed execution and not as a successful execution of the lambda. Is there any way to return 401 without failing the lambda ?
Also tried the following like in lambda integration but didn't work:
return {"statusCode": 401, "body" : "Unauthorized"}