python - AWS Python 层在本地运行
问题描述
如何在本地运行带有层的 AWS Lambda 函数?
我的环境:
- 带有 Python 3.6 运行时的 AWS Lambda 函数的 Pycharm 项目。
- AWS 工具包
- 创建 Lambda 层的类似文件/文件夹结构:https ://aws.amazon.com/blogs/compute/working-with-aws-lambda-and-lambda-layers-in-aws-sam/如下:
+---.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 的所有可能资源,但没有任何帮助。
有人可以帮忙吗?
谢谢,
解决方案
通过将符号链接添加到另一个包含图层代码的目录,我能够在 PyCharm 中解决这个问题
推荐阅读
- sas - 为生存分析 SAS 展开数据
- mysql - 使用表中的数据查询 MySQL
- android-studio - 当前帧到位图 - Arcore Android Studio - OCR AR 应用
- typescript - 打字稿:对象具有不同的键,相同的类型-如何避免在界面中重新定义整个对象?
- r - 使用 R 中的 formattable 将标题添加到表中
- java - 使用 Jackson 库动态处理请求参数
- reactjs - 如何在不使用输入标签的情况下获取文件对象
- node.js - 警告代码=H27 desc="客户端请求中断" | 主页
- javascript - 如何使对象在 p5.js 中以随时间减少的间隔出现
- angular - 根据行的属性为行指定颜色