在 AWS Lambda 上使用的加密包中找不到恒定时间模块
Can't find a constant-time module in cryptography package used on AWS Lambda
[我是 Python 2.7 和 AWS Lambda 的新手,感谢任何帮助]
我遵循 AWS Lambda tutorial 并创建了一个 virtualenv 以包含 Python 与使用 paramiko 相关的库,将文件作为 AWS Lambda 上的计划任务复制到 SFTP 服务器 运行 以下脚本:
import paramiko
def worker_handler(event, context):
host = "sftpserver.testdpom.com"
port = 22
transport = paramiko.Transport((host, port))
sftp = paramiko.SFTPClient.from_transport(transport)
username = "xxxx"
password = "xxxxxx"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put("test.txt", "test.txt")
sftp.close()
transport.close()
return
{
'message' : "Script execution completed. See Cloudwatch logs for complete output"
}
python 脚本在我的本地机器上运行正常,但是当我在 AWS Lambda 上测试包时,我收到错误 "ImportError: No module named _constant_time" 和下面的堆栈跟踪。
您能想到在 AWS Lambda 环境中出现此错误的任何可能原因吗?
File "/var/task/paramiko/kex_group1.py", line 111, in _parse_kexdh_reply
self.transport._verify_key(host_key, sig)
File "/var/task/paramiko/transport.py", line 1617, in _verify_key
key = self._key_info[self.host_key_type](Message(host_key))
File "/var/task/paramiko/rsakey.py", line 58, in __init__
).public_key(default_backend())
File "/var/task/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
_default_backend = MultiBackend(_available_backends())
File "/var/task/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
"cryptography.backends"
File "/var/task/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/var/task/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/var/task/cryptography/hazmat/backends/openssl/backend.py", line 15, in <module>
from cryptography import utils, x509
File "/var/task/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/var/task/cryptography/x509/base.py", line 15, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "/var/task/cryptography/x509/extensions.py", line 19, in <module>
from cryptography.hazmat.primitives import constant_time, serialization
File "/var/task/cryptography/hazmat/primitives/constant_time.py", line 9, in <module>
from cryptography.hazmat.bindings._constant_time import lib
ImportError: No module named _constant_time
由于 lambda 在亚马逊 linux 实例上运行,您基本上需要:
- 启动亚马逊 linux ec2 实例
- 创建一个 virtualenv 和
pip install
你需要的所有包
scp
文件到本地部署包所在的位置
这一切都是由于 pip install
如何根据您使用 linux 或 mac 做不同的事情而发生的(我假设 windows以及)。
这是一个让 ec2 实例加速 afaik 的启动脚本
#!/bin/bash
sudo yum upgrade -y
sudo yum group install -y "Development tools"
sudo yum install -y \
python27 \
libffi libffi-devel \
openssl openssl-devel
virtualenv venv
source venv/bin/activate
pip install paramiko
paramiko
包将在 /path/to/venv/lib/python2.7/site-packages/paramiko
中,cryptography
内容将在 path/to/venv/lib64/python2.7/cryptography
.
中
我一直在本地 mac 上使用 pip install
的组合,并在某个包不起作用时执行此操作(例如 paramiko
和 psycopg2
),还有一些其他有用的包,人们已经预编译并放在 github 其他地方,专门用于 lambda。
HTH!
[我是 Python 2.7 和 AWS Lambda 的新手,感谢任何帮助]
我遵循 AWS Lambda tutorial 并创建了一个 virtualenv 以包含 Python 与使用 paramiko 相关的库,将文件作为 AWS Lambda 上的计划任务复制到 SFTP 服务器 运行 以下脚本:
import paramiko
def worker_handler(event, context):
host = "sftpserver.testdpom.com"
port = 22
transport = paramiko.Transport((host, port))
sftp = paramiko.SFTPClient.from_transport(transport)
username = "xxxx"
password = "xxxxxx"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put("test.txt", "test.txt")
sftp.close()
transport.close()
return
{
'message' : "Script execution completed. See Cloudwatch logs for complete output"
}
python 脚本在我的本地机器上运行正常,但是当我在 AWS Lambda 上测试包时,我收到错误 "ImportError: No module named _constant_time" 和下面的堆栈跟踪。
您能想到在 AWS Lambda 环境中出现此错误的任何可能原因吗?
File "/var/task/paramiko/kex_group1.py", line 111, in _parse_kexdh_reply
self.transport._verify_key(host_key, sig)
File "/var/task/paramiko/transport.py", line 1617, in _verify_key
key = self._key_info[self.host_key_type](Message(host_key))
File "/var/task/paramiko/rsakey.py", line 58, in __init__
).public_key(default_backend())
File "/var/task/cryptography/hazmat/backends/__init__.py", line 35, in default_backend
_default_backend = MultiBackend(_available_backends())
File "/var/task/cryptography/hazmat/backends/__init__.py", line 22, in _available_backends
"cryptography.backends"
File "/var/task/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/var/task/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/var/task/cryptography/hazmat/backends/openssl/backend.py", line 15, in <module>
from cryptography import utils, x509
File "/var/task/cryptography/x509/__init__.py", line 7, in <module>
from cryptography.x509.base import (
File "/var/task/cryptography/x509/base.py", line 15, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "/var/task/cryptography/x509/extensions.py", line 19, in <module>
from cryptography.hazmat.primitives import constant_time, serialization
File "/var/task/cryptography/hazmat/primitives/constant_time.py", line 9, in <module>
from cryptography.hazmat.bindings._constant_time import lib
ImportError: No module named _constant_time
由于 lambda 在亚马逊 linux 实例上运行,您基本上需要:
- 启动亚马逊 linux ec2 实例
- 创建一个 virtualenv 和
pip install
你需要的所有包 scp
文件到本地部署包所在的位置
这一切都是由于 pip install
如何根据您使用 linux 或 mac 做不同的事情而发生的(我假设 windows以及)。
这是一个让 ec2 实例加速 afaik 的启动脚本
#!/bin/bash
sudo yum upgrade -y
sudo yum group install -y "Development tools"
sudo yum install -y \
python27 \
libffi libffi-devel \
openssl openssl-devel
virtualenv venv
source venv/bin/activate
pip install paramiko
paramiko
包将在 /path/to/venv/lib/python2.7/site-packages/paramiko
中,cryptography
内容将在 path/to/venv/lib64/python2.7/cryptography
.
我一直在本地 mac 上使用 pip install
的组合,并在某个包不起作用时执行此操作(例如 paramiko
和 psycopg2
),还有一些其他有用的包,人们已经预编译并放在 github 其他地方,专门用于 lambda。
HTH!