I am trying to make a custom python authorizer with payload format 2.0, right now I'm keeping it really simple and just returning the json "{isAuthorized:true}" regardless of what token is presented.
However, I am still getting failures in cloudwatch saying that the format is incorrect..
I've tried "isAuthorized" as a simple response as well.
I am using the Simple response mode.
Here is the simple python authorizer:
import os
import re
import json
import logging
import base64
import boto3
def lambda_handler(event, context):
try:
response = "{isAuthorized:True}"
y = json.dumps(response)
return y;
except:
return "";
I've also tried it without the json.dumps like this:
...
try:
response = {"isAuthorized": True}
return response;
...
Here's the error in CloudWatch:
The response from the Lambda Authorizer function doesn't match the format that API Gateway expects. Simple response did not include 'isAuthorized'
Any idea what I'm doing wrong?
CodePudding user response:
You are returning it as a string, which is not even a valid JSON.
You can try with:
response = {"isAuthorized":True}
y = json.dumps(response)
or
y = {"isAuthorized":True}