AWS Python层在本地运行

dev*_*yer 6 python layer amazon-web-services aws-lambda

如何在本地运行具有层的 AWS Lambda 函数?

我的环境:

    +---.aws-sam
        ....
    +---test
    |       app.py
    |       requirements.txt
    |       
    +---dependencies
    |   \---python
    |           constants.py
    |           requirements.txt
    |           sql.py
    |           utils.py
Run Code Online (Sandbox Code Playgroud)
  • 和部署模板如下:
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
Run Code Online (Sandbox Code Playgroud)

我可以正确部署该函数并且在 AWS 上运行它效果很好,每当我尝试在本地运行该函数时,它都会失败并显示错误消息:

`Unable to import module 'app': No module named 'sql'`
Run Code Online (Sandbox Code Playgroud)

我尝试阅读有关 Layers 和 Pycharm 的所有可能的资源,但没有任何真正的帮助。

有人可以帮忙吗?

谢谢你,

小智 3

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