"""TODO.""" import importlib import os import sys import tarfile from urllib.parse import urlparse import boto3 def _load_remote_project_archive(project_zip_path, project_name): """Load the S3 archive into the local fs and insert it into the path.""" project_folder = '/tmp/{0!s}'.format(project_name) print('Using project folder: ', project_folder) if not os.path.isdir(project_folder): result = urlparse(project_zip_path) remote_bucket = result.netloc remote_file = result.path.strip('/') print('Locating archive in s3: ', remote_bucket, remote_file) s3 = boto3.Session().resource('s3') archive_on_s3 = s3.Object(remote_bucket, remote_file).get() with tarfile.open(fileobj=archive_on_s3['Body'], mode='r|gz') as t: t.extractall(project_folder) sys.path.insert(0, project_folder) print('Using path: ', sys.path) os.chdir(project_folder) def lambda_handler(event, context): """Entry point. Loads settings from deployed zappa_settings.py.""" zappa_settings = importlib.import_module('zappa_settings') _load_remote_project_archive( zappa_settings.ARCHIVE_PATH, zappa_settings.PROJECT_NAME ) from index import handler return handler(event, context)