从具有AWS Gateway API代理的Python AWS Lambda重定向

时间:2019-03-06 11:29:31

标签: python aws-lambda aws-api-gateway

在这里发布是因为我无法进行重定向。使用链接到Python Lambda函数的AWS API Gateway作为代理,只会返回响应和标头json。这是代码

import json

def lambda_handler(event, context):
    response = {}
    response["statusCode"]=301
    response["headers"]=[{"key": 'Location',"value": 
     'https://www.google.com'}]
    data = {}
    response["body"]=json.dumps(data)
return response

有什么帮助吗?

谢谢

1 个答案:

答案 0 :(得分:0)

Mixed documentation on the web which was confusing. The syntax for specifying the redirect using Location needs to be the following when using Python:

import json

def lambda_handler(event, context):   
    response = {}
    response["statusCode"]=302
    response["headers"]={'Location': 'https://www.google.com'}
    data = {}
    response["body"]=json.dumps(data)
    return response
相关问题