简体   繁体   中英

how can I customize error response from aws authorizer function?

I have written a lambda authorizer function that calls two custom authorization services to validate the input token. So, from lambda authorizer, I want to return different possible messages for the status code 401. For example,

"INVALID credentials", "Missing Credentials", "Token Revoked".

But, In case of Unauthorized, is there any way of customising the error messages?

Yes, see the help files here

There is a python example provided that returns a json/dict structure. You can do the same to return your status code and message/s when the user is unauthorized.

def lambda_handler(event, context):
json_region = os.environ['AWS_REGION']
return {
    "statusCode": 200,
    "headers": {
        "Content-Type": "application/json"
    },
    "body": json.dumps({
        "Region ": json_region
    })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM