Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python AWS Lambda 301 redirect

I have a lambda handler written in Python and I wish to perform a 301 redirect to the browser. I have no idea how I can configure the response Location header (or the status code) -- the documentation doesn't seem to cover anything in context object other than some properties. Apparently context.succeed works with Node JS but this doesn't help in Python.

Returning:

{"Location": "http://google.com/"}

causes the API gateway to report:

Fri Dec 09 16:20:53 UTC 2016 : Execution failed due to configuration error: Malformed Lambda proxy response

in the test console.

So, how do I perform a 301 redirect from a Python Lambda function when using API gateway and an "AWS Lambda Proxy" integration request?

like image 630
Alex Avatar asked Dec 09 '16 16:12

Alex


1 Answers

Turns out I need to manually map the response header and the response code in the integration response. The following post helped me get what I wanted: https://kennbrodhagen.net/2016/04/02/how-to-return-302-using-api-gateway-lambda/

like image 144
Alex Avatar answered Sep 30 '22 00:09

Alex