4

We have an Angular SPA front end, which communicates through an AWS API Gateway to a .Net Web API hosted in a Lambda function. This configuration mandates that our API Gateway uses proxy intgeration with the Lambda.

Generally, this works well. We have enabled CORS in our API, and normal requests and responses flow as expected.

However, when something happens that breaks the API Gateway or .Net Lambda Wrapper, such as exceeding the Gateway's (non-configurable) 30-second timeout, or exceeding Lambda's max response size, the response message from the API Gateway does not contain a CORS header. As a result, regardless of the actual error, our front end registers a CORS error.

Is there some way to configure the API Gateway to always return a default CORS header?

Please note that this is happening outside of our code - there is nothing I can do inside of the C# lambda function, as this relates to errors happening above that level.

SouthShoreAK
  • 4,176
  • 2
  • 26
  • 48

1 Answers1

4

Yes, you can set it at AWS API Gateway Level

  1. Login to AWS Console, Open API Gateway Service, Select your desired gateway.
  2. On the left-hand side panel, select "Gateway Responses" (this will appear under your selected gateway)
  3. now on the right-hand side, select "Default 5XX"
  4. Add Default Headers for Cors like Access-Control-Allow-Headers, Access-Control-Allow-Methods, Access-Control-Allow-Origin
  5. Save the changes and re-deploy the gateway.

Please refer this image to navigate to the desired section

Hope it helps.