AWS Python层在本地运行

时间:2019-09-16 11:35:06

标签: python amazon-web-services aws-lambda layer

如何在本地运行带有图层的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的所有可能资源,但没有任何帮助。

有人可以帮忙吗?

谢谢

1 个答案:

答案 0 :(得分:1)

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