I'm developing an API Gateway AWS with PyCharm in python. I'm using AWS Dev Tools and I've started to create Hello World template, which works fine. Then now I will add a python module that I developed and I want to deploy it to make it available to lambda functions. That's the project structure:
├── __init__.py
├── library_common
│ ├── __init__.py
│ ├── configuration.py
│ └── encryption.py
├── events
│ └── event.json
├── keepalive_functions
│ ├── __init__.py
│ ├── app.py
│ └── requirements.txt
├── requirements.txt
├── samconfig.toml
├── template.yaml
├── tests
│ ├── __init__.py
│ ├── integration
│ │ ├── __init__.py
│ │ └── test_api_gateway.py
│ ├── requirements.txt
│ └── unit
│ ├── __init__.py
│ └── test_handler.py
Basically, I want to use functions in library_common when I call lambda function in keepalive_functions.
Next template.yaml text:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
entry365anchor
Sample SAM Template for entry365anchor
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
GetKeepalive:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: keepalive_functions/
Handler: app.get_keepalive
Runtime: python3.8
Events:
PutResource:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /v1/keepalive
Method: get
Running method I incurred in this error:
{"errorMessage": "Unable to import module 'app': No module named 'entry365common'", "errorType": "Runtime.ImportModuleError", "stackTrace": []}
Thanks for your help.