0

I want to SSH into EC2 instance through Lambda function, I have created a layer for paramiko library. The lambda function picks up the library but it gives me this error:

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

I have increased the Memory size to 512 MB and I have created the paramiko layer using Amazon Linux 2 so it wont have any dependencies issue

Connecting to EC2 through Lambda

0

1 Answer 1

0

Another option i would suggest is to use AWS SSM to trigger operations in EC2 from lambda function.

References: https://aws.amazon.com/getting-started/hands-on/remotely-run-commands-ec2-instance-systems-manager/

https://medium.com/@Electricste/run-shell-commands-on-a-ec2-from-a-lambda-function-108994911064

Sign up to request clarification or add additional context in comments.

1 Comment

I think that is the better option and is next on the list but I want to resolve this issue as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.