英文:
Unable to import module 'lambda_function': No module named 'parameter_store_extension'
问题
# resumebuilder_utils.zip
.
├── __pycache__
│ ├── __init__.cpython-310.pyc
│ └── utils.cpython-310.pyc
├── python
│ └── lib
│ └── python3.10
│ └── site-packages
├── requirements.txt
└── utils.py
# parameter_store_extension.zip
.
└── parameter_store_extension.py
# parameter_store_extension.py
import urllib
import json
import os
from urllib.parse import urlencode
aws_session_token = os.environ.get('AWS_SESSION_TOKEN')
port = '2773';
def get_param(name: str):
"""
Get SALT form systems manager/parameter store
"""
params = dict(name=name)
req = urllib.request.Request(
f"http://localhost:{port}/systemsmanager/parameters/get/?{urlencode(params)}&withDecryption=true")
req.add_header('X-Aws-Parameters-Secrets-Token', aws_session_token)
config = urllib.request.urlopen(req).read()
return json.loads(config)
英文:
I created two lambda layers. Both from zip files, in which the first one includes python dependencies
# resumebuilder_utils.zip
.
├── __pycache__
│ ├── __init__.cpython-310.pyc
│ └── utils.cpython-310.pyc
├── python
│ └── lib
│ └── python3.10
│ └── site-packages
├── requirements.txt
└── utils.py
My lambda function can use the functions inside utils.py
like this
from utils import hash_password, normalize_value_object
As for the second layer, this one does not need any dependencies since it only consists of one file
# parameter_store_extension.zip
.
└── parameter_store_extension.py
# parameter_store_extension.py
import urllib
import json
import os
from urllib.parse import urlencode
aws_session_token = os.environ.get('AWS_SESSION_TOKEN')
port = '2773'
def get_param(name: str):
"""
Get SALT form systems manager/parameter store
"""
params = dict(name=name)
req = urllib.request.Request(
f"http://localhost:{port}/systemsmanager/parameters/get/?{urlencode(params)}&withDecryption=true")
req.add_header('X-Aws-Parameters-Secrets-Token', aws_session_token)
config = urllib.request.urlopen(req).read()
return json.loads(config)
However, I cannot use functions inside parameter_store_extension.py
, as I do with the first layer.
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'parameter_store_extension'
答案1
得分: 0
我应该将 parameter_store_extension.py
移动到 python/lib/python3.10/site-packages/
再进行压缩。
英文:
my mistake, I should move the parameter_store_extension.py
inside python/lib/python3.10/site-packages/
before zipping
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论