Add api config to customize API Gateway Responses
See original GitHub issueThere is a need and use for customizing API Gateway Responses in Chalice. Specifically, I mean the ones you can currently edit in the console on this page:
So you can set custom status response codes, headers, and possibly templates.
I’d started #1270 to try implementing it, but @stealthycoin it would be good to discuss the implementation in an issue. In the pr I tried implementing it in the chalice config, but as was pointed out, it would be more appropriate for this to be managed on the app itself, e.g.
app = Chalice(app_name="helloworld")
app.api.<yet to be named> = <some config we haven't defined yet>
So some things we need to address in this issue are:
- What should the name of the property on
app.api
be?- I personally like something like
gateway_responses
, but am open to other people’s input.
- I personally like something like
- How should this configuration be defined? There is the option of JSON, which as pointed out in the pr, is not as friendly. @stealthycoin suggested using a dict to define it. Here is a link to the possible values that we could define: https://docs.aws.amazon.com/apigateway/api-reference/resource/gateway-response/#properties
- I agree that this should be a dict, and we could make it a mapping of response types to config options. E.g.
Maybe this is too verbose? I’d be happy to get some feedback or alternative options.app.api.gateway_responses = { 'default_4xx': { 'response_parameters': { 'access-control-allow-origin': "'*'" } } }
- I agree that this should be a dict, and we could make it a mapping of response types to config options. E.g.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Gateway responses in API Gateway - AWS Documentation
Learn how to set up gateway responses to customize error responses.
Read more >Gateway responses in API Gateway - 亚马逊云科技
Setting up gateway responses to customize error responses ... In the API Gateway REST API, a gateway response is represented by the GatewayResponse....
Read more >Adding a Gateway Response - 华为云
Scenario · The default gateway responses provided by API Gateway can be edited. · You can create gateway responses and configure different ...
Read more >How to change API Gateway response - Stack Overflow
3 Answers 3 · Go to API Gateway in AWS Management Console. · Select your API. · Click "Gateway Responses" which can be...
Read more >REST API (API Gateway v1) - Serverless Framework
Manually Configuring shared API Gateway ... To create HTTP endpoints as Event sources for your AWS Lambda Functions, ... callback(null, response);.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Forgot to say that one of the big reasons for being able to do this is so that you can set up Default 4XX and 5XX response parameters for CORS setup.
+1 for this requirement.
In my scenario i’m using a customer Lambda Authoriser… if the lambda authorizor rejects the users then it will trigger the default API responses, and without a means to customize the Response template, there’s no means to return meaningful response details.