如何在本地运行带有层的 AWS Lambda 函数?
我的环境:
+---.aws-sam
....
+---test
| app.py
| requirements.txt
|
+---dependencies
| \---python
| constants.py
| requirements.txt
| sql.py
| utils.py
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
我可以正确部署该函数并且在 AWS 上运行它运行良好,
每当我尝试在本地运行该函数时,它都会失败并显示错误消息:
`Unable to import module 'app': No module named 'sql'`
我尝试阅读有关 Layers 和 Pycharm 的所有可能资源,但没有任何帮助。
有人可以帮忙吗?
谢谢,
最佳答案
通过向包含该层代码的另一个目录添加符号链接(symbolic link),我能够在 PyCharm 中解决此问题
关于python - AWS Python 层在本地运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57955983/