Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Authorizer with API Gateway

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading