Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Gateway lambda authorizer custom status code

I have a question about API Gateway authorizers and lambda functions.

My scenario is the following: I have a resource in AWS API Gateway for which the authorization is enabled. The authorizer calls a lambda function which, if the user is not authorized, redirects the user to another URL.

So basically I would like to customize the authorizer to return a 302 rather than a 401/403/500 status code. Do you know if that is possible?

I know that having a lambda function in the integration phase of the gateway lets me customize the response. What about this particular scenario?

Thanks.

like image 555
TheRock3t Avatar asked Nov 18 '22 13:11

TheRock3t


1 Answers

You cannot change status code or headers through Lambda Authorizer, but you can do it through Gateway Responses.

  1. Go to API Gateway
  2. Select the API you want to change
  3. On the left panel, select Gateway Responses
  4. Select the Response you want to override (e.g. UNAUTHORIZED)
  5. Click Edit on the right panel

You can now redefine the response status, headers and body as you like.

Full documentation: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-gateway-response-using-the-console.html

like image 184
paulodiovani Avatar answered Dec 20 '22 21:12

paulodiovani