This should be pretty easy if you’re using the (default) Lambda Proxy integration for your function.
Here’s a code example in the AWS docs.
Basically:
- Set your
responseCodeto “302” and include aLocationkey/value in yourheadersto point them to the new location. - If nothing is found, just change the
responseCodeto 404. - Don’t forget to stringify your
body(for the error message) - I aways do.