Customizing REST API Gateway Authorizer Response

0

Hi Folks,

I am looking to output a specific error message when I raise a Deny policy from my lambda authorizer hooked up to my REST API Gateway. There are a couple of different 403 responses in the API gateway, I am trying to find the right one which the API raises when my authorizer returns a deny policy.

Thanks, Matthew

1개 답변
0

Yes, you can return a specific response from Lambda Authorizer, you have access to a special object called $context.authorizer which you can use to customize the response, please review this section of the documentation which explains in depth, you can use in your response template.

In the API Gateway console you can change the response to custom for Access Denied (403), Under the Response templates -> Template body you can specify the specific field being returned from your authorizer, In my case, I have a authorizer for my API where I return a message field populated with a custom message under the context key for denied requests, so my Template body is {"message":$context.authorizer.context.message}

I have this field populated with this specific string "context": {... "message": "You do not have access to this resource"} so when authorizer denies the request, the response I get is {"message":You do not have access to this resource}

Please see this SO post as well that explains it.

HTH

AWS
jay-aws
답변함 2달 전
profile picture
전문가
검토됨 2달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠