question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add api config to customize API Gateway Responses

See original GitHub issue

There 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:

image

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:

  1. 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.
  2. 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.
      app.api.gateway_responses = {
          'default_4xx': {
              'response_parameters': {
                  'access-control-allow-origin': "'*'"
              }
          } 
      }
      
      Maybe this is too verbose? I’d be happy to get some feedback or alternative options.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
felipe-leecommented, Oct 19, 2019

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.

0reactions
alexevansiggcommented, Dec 6, 2021

+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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found