I want to connect EC2 using pysftp library via AWS Lambda. I use below code to connect.
mysftp = pysftp.Connection(
host=Constants.MY_HOST_NAME,
username=Constants.MY_EC2_INSTANCE_USERNAME,
private_key="./clientiot.pem",
cnopts=cnopts,
)
I have put .pem file along with deployment package in AWS Lambda. See this image:
Sometimes it works sometime not, like sometimes it says .pem file not found.
"[Errno 2] No such file or directory: './clientiot.pem'"
How to deal with it? Is there any way to access .pem file or data of .pem file securely.
I don't want .pem in AWS lambda.