AWS Python层在本地运行

问题描述 投票:0回答:1

如何使用层在本地运行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'`

我已经尝试阅读有关图层和Pycharm的所有可能的资源,但没有什么真正的帮助。

有人可以帮忙吗?

谢谢,

python amazon-web-services aws-lambda layer
1个回答
0
投票

我能够通过在包含该层代码的另一个目录中添加符号链接来解决PyCharm中的此问题

© www.soinside.com 2019 - 2024. All rights reserved.