使用 paramiko 库通过 AWS Lambda SSH 到 EC2

问题描述 投票:0回答:1

我想通过 Lambda 函数 SSH 到 EC2 实例,我已经为 paramiko 库创建了一个层。 lambda 函数获取了库,但它给了我这个错误:

Response
{
  "errorType": "Runtime.ExitError",
  "errorMessage": "RequestId: 26d4c295-51f8-4d98-b698-277a3e43336d Error: Runtime exited with error: exit status 1"
}

Function Logs
ACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 480, in <module>
main()
File "/var/runtime/bootstrap.py", line 452, in main
request_handler = _get_handler(handler)
File "/var/runtime/bootstrap.py", line 46, in _get_handler
m = imp.load_module(modname, file_handle, pathname, desc)
File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/lambda_function.py", line 3, in <module>
import paramiko
File "/opt/python/lib/python3.8/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import (
File "/opt/python/lib/python3.8/site-packages/paramiko/transport.py", line 33, in <module>
from cryptography.hazmat.primitives.ciphers import algorithms, Cipher, modes
File "/opt/python/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py", line 11, in <module>
from cryptography.hazmat.primitives.ciphers.base import (
File "/opt/python/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 10, in <module>
from cryptography.exceptions import (
File "/opt/python/lib/python3.8/site-packages/cryptography/exceptions.py", line 9, in <module>
from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
pyo3_runtime.PanicException: Python API call failed
ModuleNotFoundError: No module named '_cffi_backend'
thread '<unnamed>' panicked at 'Python API call failed', /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pyo3-0.18.3/src/err/mod.rs:790:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
File "/var/runtime/bootstrap.py", line 480, in <module>
main()
File "/var/runtime/bootstrap.py", line 452, in main
request_handler = _get_handler(handler)
File "/var/runtime/bootstrap.py", line 46, in _get_handler
m = imp.load_module(modname, file_handle, pathname, desc)
File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/lambda_function.py", line 3, in <module>
import paramiko
File "/opt/python/lib/python3.8/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import (
File "/opt/python/lib/python3.8/site-packages/paramiko/transport.py", line 33, in <module>
from cryptography.hazmat.primitives.ciphers import algorithms, Cipher, modes
File "/opt/python/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py", line 11, in <module>
from cryptography.hazmat.primitives.ciphers.base import (
File "/opt/python/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 10, in <module>
from cryptography.exceptions import (
File "/opt/python/lib/python3.8/site-packages/cryptography/exceptions.py", line 9, in <module>
from cryptography.hazmat.bindings._rust import exceptions as rust_exceptions
pyo3_runtime.PanicException: Python API call failed
START RequestId: 26d4c295-51f8-4d98-b698-277a3e43336d Version: $LATEST
RequestId: 26d4c295-51f8-4d98-b698-277a3e43336d Error: Runtime exited with error: exit status 1
Runtime.ExitError
END RequestId: 26d4c295-51f8-4d98-b698-277a3e43336d
REPORT RequestId: 26d4c295-51f8-4d98-b698-277a3e43336d  Duration: 939.93 ms Billed Duration: 940 ms Memory Size: 512 MB

我已将内存大小增加到 512 MB,并使用 Amazon Linux 2 创建了 paramiko 层,因此它不会有任何依赖项问题

通过 Lambda 连接到 EC2

amazon-web-services aws-lambda ssh paramiko
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.