I have a Lambda function that invokes after an S3 object put. It connecting to another EC2 instance and running a bash script. I've confirmed the bash script, and Python code outside of the lambda function work as they should. Wrapping it however produces the same error that I can't figure out. The role attached to the lambda appears to have all required EC2 and S3 required policies attached. No VPC is attached to the lambda function either.
Code:
import boto3
import botocore
import paramiko
def lambda_handler(event, context):
s3_client = boto3.client('s3')
s3_client.download_file('mycluster', 'keys/ec2box.pem',
'/tmp/ec2box.pem')
k = paramiko.RSAKey.from_private_key_file('/tmp/ec2box.pem')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname='99.99.9999', username='centos', pkey=k)
commands = [
"cd /home/dir1/;chmod +x file.sh;nohup ./file.sh > logs/program"
]
for command in commands:
print
"Executing {}".format(command)
stdin, stdout, stderr = c.exec_command(command)
print
stdout.read()
print
stderr.read()
return
{
'message': "Script execution completed. See Cloudwatch logs for complete output"
}
My Error
[Errno 110] Connection timed out: error
Traceback (most recent call last):
File "/var/task/pythonprogram.py", line 17, in lambda_handler
c.connect(hostname='99.99.9999', username='centos', pkey=k)
File "/var/task/paramiko/client.py", line 338, in connect
retry_on_signal(lambda: sock.connect(addr))
File "/var/task/paramiko/util.py", line 279, in retry_on_signal
return function()
File "/var/task/paramiko/client.py", line 338, in <lambda>
retry_on_signal(lambda: sock.connect(addr))
File "/usr/lib64/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 110] Connection timed out
Any ideas?