def _generate_lambda_handler(config, output='.slam/handler.py'):
"""Generate a handler.py file for the lambda function start up."""
# Determine what the start up code is. The default is to just run the
# function, but it can be overriden by a plugin such as wsgi for a more
# elaborated way to run the function.
run_function = _run_lambda_function
for name, plugin in plugins.items():
if name in config and hasattr(plugin, 'run_lambda_function'):
run_function = plugin.run_lambda_function
run_code = ''.join(inspect.getsourcelines(run_function)[0][1:])
# generate handler.py
with open(os.path.join(os.path.dirname(__file__),
'templates/handler.py.template')) as f:
template = f.read()
template = render_template(template, module=config['function']['module'],
app=config['function']['app'],
run_lambda_function=run_code,
config_json=json.dumps(config,
separators=(',', ':')))
with open(output, 'wt') as f:
f.write(template + '\n')
评论列表
文章目录