来自资源策略的AWS API Gateway更改访问被拒绝响应消息 [英] AWS API Gateway change access denied response message from resource policy

查看:355
本文介绍了来自资源策略的AWS API Gateway更改访问被拒绝响应消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从AWS API Gateway资源策略错误中更改默认的403正文?

how can the default 403 body be changed from an AWS API Gateway resource policy error?

{"Message":"User: anonymous is not authorized to perform: execute-api:Invoke on resource:... with an explicit deny"}

推荐答案

您可以使用

You can make use of Gateway Responses in API Gateway to modify the HTTP status code and response that goes back to a client.

默认情况下,对于您描述的情况,响应是您看到的大消息,状态码为403.要更改此设置-

By default, for the scenario you have described, the response is the big message you see and status code is 403. To change this -

  1. 转到您的API左列的网关响应".
  2. 选择拒绝访问",然后单击右上角的编辑".
  3. 单击响应模板"下的"application/json".
  4. 在响应正文模板"部分中,将消息修改为{"message":您的自定义消息"}.
  5. 部署API并等待一分钟,以传播更改.

如果您看到下面的图片,我已将状态代码更改为401,并将消息更改为未经授权".

If you see the image below, I have changed the status code to 401 and message to "Unauthorized".

这篇关于来自资源策略的AWS API Gateway更改访问被拒绝响应消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆