Search code examples
python-3.xamazon-web-servicesaws-lambdaamazon-lex

Importing Python files in Aws Lambda causes error


I'm currently in a school course where we have to do a software project for some client. Our project is a helper bot powered by Amazon Lex service and Amazon's Lambda function. Our issue is that for some reason the Lambda function does not have same kind of syntax for importing files that other Python 3.6 programs have. This causes problems because TravisCI won't build properly due to the different syntax and errors caused by it.

In the Lambda function the import needs to looks like this:

from custom_python_file import CustomClass

But in TravisCI, and I believe every in also everyother other platform it needs to be typed like this:

from .custom_python_file import CustomClass

We tried to do some workarounds, but none did work.

Any help?


Solution

  • In Python . is used for relative imports. It simply means that it is importing from the same package.

    Refer this tutorial and this question for the same.