Open
Description
Problem:
Using per-function requirements according to the explanation on the web page.
I'm encountering this strange problem in which packaging generates TWO zip files per function. One of the two zips contains the included files from the local source code. The other one contains the handler.py and the pip requirements.
Delatils:
Project structure:
- serverless.yml
- lambda_1/
- handler.py
- requirements.txt
- lambda_2/
- handler.py
- requirements.txt
- shared/
- __init__.py
- shared_module.py
Snippet from serverless.yml
package:
individually: true
exclude:
- '**'
functions:
ShortFunctionName1: # the shorthand name we use to refer to the function within serverless.yml
name: fully-qualified-function-name-1 # the fully qualified function name used in AWS Lambda
module: lambda_1
package:
include:
- 'shared/**'
- 'lambda_1/**'
handler: handler.handle_lambda_event
ShortFunctionName2:
name: fully-qualified-function-name-2
module: lambda_2
package:
include:
- 'shared/**'
- 'lambda_2/**'
handler: handler.handle_lambda_event
What happens during packaging is the following:
- packaging generates 2 zip files per function:
- ShortFunctionName1.zip --> contains the files matching the include patterns
lambda_1/
andshared/
with files underneath) - lambda_1-fully-qualified-function-name-1.zip --> contains
handler.py
from directorylambda_1/
on the root. also contains all pip requirements) - the same applies to function_2, we get one zip with the short name and one with the fully qualified name.
- ShortFunctionName1.zip --> contains the files matching the include patterns
- deployment uploads only the zip files with file fully qualified name to AWS.
- runtime you get an
ImportError
: modules underlambda_1
orshared
are obviously not found because these directories weren't packaged in this zip file.
I believe this is a bug in the packaging process, where there is inconsistent usage of the shorthand and fully qualified function names in establishing the target zip filename.
Software versions:
Serverless framework: 3.19.0
Serverless-python-requirements: 5.4.0