How does one run locally a AWS Lambda Function with layers?
My environment:
- Pycharm project for an AWS Lambda Function with Python 3.6 runtime.
- AWS Toolkit
- similar file/folder structure to create a Lambda Layer: https://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/ as follows:
+---.aws-sam
....
+---test
| app.py
| requirements.txt
|
+---dependencies
| \---python
| constants.py
| requirements.txt
| sql.py
| utils.py
- and deployment template like:
testFunc:
Type: AWS::Serverless::Function
Properties:
CodeUri: teest/
Handler: app.test
Runtime: python3.6
FunctionName: testFunc
Events:
test:
Type: Api
Properties:
Path: /test
Method: ANY
Layers:
- !Ref TempConversionDepLayer
TempConversionDepLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: Layer1
Description: Dependencies
ContentUri: dependencies/
CompatibleRuntimes:
- python3.6
- python3.7
LicenseInfo: 'MIT'
RetentionPolicy: Retain
I can deploy the function correctly and running it on AWS works well, whenever i try to run the function locally, it fails with the error message:
`Unable to import module 'app': No module named 'sql'`
I've tried to read all possible resources about Layers and Pycharm but nothing really helped.
Can anybody give a hand please?
Thank you,
import
statement inapp.py
look like? – Peter Halverson