Ryan S. Brown bfe2976d07 Allow Python functions to be run locally top-level dir
Use the real path of the running file instead of the relative path from
where the function is run.

This means `serverless function run componentnamd/modname/functionname`
works everywhere in the project, not just in the function directory.
2016-01-23 10:22:15 -05:00

23 lines
652 B
Python

from __future__ import print_function
import json
import logging
log = logging.getLogger()
log.setLevel(logging.DEBUG)
# this adds the component-level `lib` directory to the Python import path
import sys, os
# get this file's directory independent of where it's run from
here = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(here, "../../"))
sys.path.append(os.path.join(here, "../../vendored"))
# import the shared library, now anything in component/lib/__init__.py can be
# referenced as `lib.something`
import lib
def handler(event, context):
log.debug("Received event {}".format(json.dumps(event)))
return {}