Ad

Error: Timed Out While Waiting For Handshake In Lambda Logs

The function of SFTP is working locally and it has the correct configuration. The problem is with the logs of Lambda that complains about the configuration I believe by giving me an Error: Timed out while waiting for a handshake.

const config = {
    host: 'ftp.xxxx.at',
    port: '22',
    username: 'SFTP_xxx',
    password: 'xxx9fBcS45',
    MD5_Fingerprint: 'xxx:8f:5b:1a',
    protocol: "sftp",
    algorithms: {
        serverHostKey: ['ssh-rsa', 'ssh-dss']
      }
};


// get file
// get sftp file
// here ....
const get = () => {
    sftp.connect(config).then(() => {
        return sftp.get('./EMRFID_201811210903.csv', null, 'utf8', null);
    }).then((stream) => {
        let body = stream.on('data', (chunk) => {
            body += chunk;
        })
        stream.on('end', () => {

            uploadRFIDsToS3(body)
            // close connection
            sftp.end()
        });
    }).catch((err) => {
        console.log('catch err:', err)
    })
};

-

vpc:
  securityGroupIds:
  - sg-01c29be1d8fbxx59 

  subnetdIds:
  - subnet-007a88d9xxea434d

-

2019-02-18T13:53:51.121Z    e688c7bd-24fc-45a1-a565-f2a4c313f846    catch err: { Error: Timed out while waiting for handshake
at Timeout._onTimeout (/var/task/node_modules/ssh2-sftp-client/node_modules/ssh2/lib/client.js:695:19)
at ontimeout (timers.js:482:11)
at tryOnTimeout (timers.js:317:5)
at Timer.listOnTimeout (timers.js:277:5) level: 'client-timeout' }

I added VPC and Security Group in AWS and I still get the same error. I ran out of ideas of how to fix it.

Ad

Answer

I figure it out. What was wrong is that Lambda was actually going to another function without getting the connection established. So what I did is that I added await to the connection and other functions that should not interfere with each other to make to work.

To understand more about await go to this link: https://javascript.info/async-await

Ad
source: stackoverflow.com
Ad