Is it possible to return 401 error from WebSocket API Gateway Lambda Authorizer without throwing an error?

0

Hello, we are using WebSocket API Gateway Lambda Authorizer to authorise the users and we throw an Unauthorized error when the cookie is invalid (related AWS doc). But this increases AWS/Lambda Errors metrics which triggers our alarms and we don't want to turn this alarm off because we want to be notified about any function errors. Is it possible to return 401 HTTP status code to client from API Gateway but without throwing an error from Authorizer? Any CloudFormation example code is appreciated.

I know we can use Deny Policy document but this results in 403 status code which is not what we want.

Thanks

1 回答
1

Hello,

I understand that you want Websocket API to return 401 status code to client, without returning unauthorized error response from Lambda authorizer. REST API supports Gateway Response, which can be used to modify 403 status code from lambda authorizer to customized error response, including 401 status code.

At this time, Websocket API does not support Gateway Response. We already have a feature request open with the service team, regarding this. While I am unable to comment on if/when this feature may get released, I request you to keep an eye on our What's New and Blog pages for any new feature announcements.

AWS
支持工程师
Isha_K
已回答 2 年前
  • Thanks for the response and links, do you have a link to that feature request? So we can follow the progress. Thanks

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则