Doing a 302 redirect in python?

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 responseCode to “302” and include a Location key/value in your headers to point them to the new location.
  • If nothing is found, just change the responseCode to 404.
  • Don’t forget to stringify your body (for the error message) - I aways do.
1 Like