[aws-lambda-python] Unify `entry` field betwen aws-lambda-nodejs and aws-lambda-python
See original GitHub issueI love the new PythonFunction support in aws-cdk! I did, however, notice a difference between how the entry
property works between aws-lambda-nodejs
and aws-lambda-python
.
In aws-lambda-nodejs
, the entry
field is a fully qualified path to the index file. From the docs:
However, the entry
and index
are broken into two distinct properties in aws-lambda-python
. From the docs:
So, when I was converting a function over to PythonFunction
, I fully specified the entry
, like I would with NodejsFunction
:
new PythonFunction(this, 'MyFunc', {
entry: path.join(__dirname, 'lambda', 'my_lambda.py')
}
But I received this error, which surprised me.
Cannot find index file at /Users/blimmer/my-project/foo/src/my-func/lambda/my_lambda.py/index.py
I fixed the problem by using entry
and index
like this:
new PythonFunction(this, 'MyFunc', {
entry: path.join(__dirname, 'lambda'),
index: 'my_lambda.py',
}
However, I believe that entry
should work the same between python and nodejs for consistency.
Use Case
Unifying the entry
property between PythonFunction
and NodejsFunction
will make it easier for developers to define both types of functions.
Proposed Solution
I propose that index
be removed from PythonFunction
and for entry
to be the fully qualified path to the index file, like it is in NodejsFunction
.
Other
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (7 by maintainers)
Top GitHub Comments
Please do not unify anything. In fact the current implementation does not work with all Python lambda code where it would make sense. In Python lambda it would make sense to have only the current meaning of
entry
and thehandler
parameter withindex
gone altogether.How the AWS Lambda Runtime for Python is realized is that it will unpack the source files into a directory that is in Python module search path. One specifies the handler in format
foo.bar.baz
. The Lambda runtime will decode this asfrom foo.bar import baz
and thereinafter usebaz
as the handler function. Now the problem is that we need to rewrite all of our lambda code that was inside modules just that we can have one.py
file in a suitable place so that it works.There are no “index files” in Python, so looking for one is misguided. In fact I’ve been writing a library that would have the handler inside it - a small framework setting up logging and such, and then calling the the actual handler function that resides in the installed source code. The handler need not even be in a file, it is just sufficient that it is something that Python can import.
The fix could be as simple as removing the index parameter and specifying that the entry must be a directory, and then just:
It is of course possible to make it work with the
index
parameter as well, if specified, but the default value is tricky.@michaelbrewer yes, and the unification they’re after in this bug would make it even more difficult to get anything like that working.