来自资源策略的AWS API Gateway更改访问被拒绝响应消息 [英] AWS API Gateway change access denied response message from resource policy
本文介绍了来自资源策略的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 -
- 转到您的API左列的网关响应".
- 选择拒绝访问",然后单击右上角的编辑".
- 单击响应模板"下的"application/json".
- 在响应正文模板"部分中,将消息修改为{"message":您的自定义消息"}.
- 部署API并等待一分钟,以传播更改.
如果您看到下面的图片,我已将状态代码更改为401,并将消息更改为未经授权".
If you see the image below, I have changed the status code to 401 and message to "Unauthorized".
这篇关于来自资源策略的AWS API Gateway更改访问被拒绝响应消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文