Python AWS Lambda 301 redirect

只谈情不闲聊 提交于 2019-12-22 08:58:00

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/41064735/python-aws-lambda-301-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!