I'm trying to access sftp server using an aws lambda function but it keeps returning null and I'm not sure why. The host, username and password are correct because I tested the connection using WinSCP. I also tried connecting to other free sftp servers but the response kept returning null. I'm not sure what I'm doing wrong in the script. I did install the npm packages, then zipped the file and uploaded the zip file to aws lambda.
exports.handler = async (event) => {
let Client = require('ssh2-sftp-client');
let Path = '/path';
let sftp = new Client();
sftp.connect({
host: 'host',
port: 22,
username: 'username',
password: 'password'
}).then(() => {
return sftp.list(Path);
}).then(() => {
context.done();
}).catch((err) => {
console.log('Catch Error: ', err);
context.fail();
});
};