Repetitive StatusCodes

I have many lambda functions using the ‘lambda’ integration type in api gateway, and all have these status code headers:

statusCodes:
          200:
            pattern: '' # JSON response
            headers:
              Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control'"
              Access-Control-Allow-Methods: "'*'"
              Access-Control-Allow-Origin: "'*'"

Is there a way in this framework to set a default status code for all the functions so I don’t have to repeat this block 100 times?

Not sure if there’s a way to set a default but you could create a ‘statusCodes’ variable in the ‘custom’ section and assign your constant object to it. Then you would only need to reference the custom variable each time rather than the whole object.

1 Like