Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect from a Python AWS Lambda with AWS Gateway API Proxy

Posting here because I just can't get a redirect working. Using AWS API Gateway linked to a Python Lambda function as a proxy just returns the response and header json. Here is the code

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

Any help will be appreciated?

Thanks

like image 308
orbital Avatar asked Mar 06 '19 11:03

orbital


1 Answers

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
like image 104
orbital Avatar answered Sep 22 '22 15:09

orbital