1回答
- 新しい順
- 投票が多い順
- コメントが多い順
1
Yes. At the end of the example authorizer in the docs (https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html), there is way to output optional data. Updating with your values, it would be something like this:
// Optional output with custom properties of the String, Number or Boolean type.
authResponse.context = {
"errorCode": "xyz_12#",
"errorType": "Constraint error",
"errorMessage": "Need permisssion to perform this action"
};
In the body mapping template, you'd access these as follows:
{"errorCode":"$context.authorizer.context.errorCode", "errorType": "$context.authorizer.context.errorCode"}
The one caveat here is that you can't specify the HTTP error code. The authorizer has to generate a 'Deny' policy which then results in an HTTP 403.
More discussion is available here: https://stackoverflow.com/questions/47921803
回答済み 2年前
関連するコンテンツ
- AWS公式更新しました 1年前
I have tried evrything and nothing works for me. I want to customize the error mesage in the lambda authorizer if the token is expired or malformed. Followed this post as well https://stackoverflow.com/questions/47921803 . This is the main problem
Another wierd problem i am facing is that the callback with custom errors also does not work in simple lambda calls. I am really tired of this. can someone please guide how to resolve. It gives me InvokeError. secondary
callback("unauthorized"); // not working return callback(new Error("JSON.stringify(myErrorObj)")); // not working
This seems to only apply for the API Gateway V1 (REST) not for the V2 (HTTP) API Gateway. I really need something like this for the V2 API Gateway and a custom authorizer
Should the mapping template be the following?