Python AWS Lambda 301重定向 [英] Python AWS Lambda 301 redirect
问题描述
我有一个用Python编写的lambda处理程序,我希望执行301重定向到浏览器.我不知道如何配置响应Location
标头(或状态代码)-该文档似乎没有涵盖上下文对象中除某些属性以外的任何内容.显然context.succeed
可与Node JS一起使用,但这在Python中无济于事.
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.
返回:
{"Location": "http://google.com/"}
使API网关进行报告:
causes the API gateway to report:
Fri Dec 09 16:20:53 UTC 2016 : Execution failed due to configuration error: Malformed Lambda proxy response
在测试控制台中.
那么,当使用API网关和"AWS Lambda代理"集成请求时,如何从Python Lambda函数执行301重定向?
So, how do I perform a 301 redirect from a Python Lambda function when using API gateway and an "AWS Lambda Proxy" integration request?
推荐答案
原来,我需要在集成响应中手动映射响应标头和响应代码.以下帖子帮助我获得了想要的东西:
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/
这篇关于Python AWS Lambda 301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!