def build_wsgi_environ_from_event(event):
"""Create a WSGI environment from the proxy integration event."""
params = event.get('queryStringParameters')
environ = EnvironBuilder(method=event.get('httpMethod') or 'GET',
path=event.get('path') or '/',
headers=event.get('headers') or {},
data=event.get('body') or b'',
query_string=params or {}).get_environ()
environ['SERVER_PORT'] = 443
if 'execute-api' in environ['HTTP_HOST']:
# this is the API-Gateway hostname, which takes the stage as the first
# script path component
environ['SCRIPT_NAME'] = '/' + event['requestContext'].get('stage')
else:
# we are using our own hostname, nothing gets added to the script path
environ['SCRIPT_NAME'] = ''
environ['wsgi.url_scheme'] = 'https'
environ['lambda.event'] = event
return environ
评论列表
文章目录