SFTP的功能在本地工作,配置正确。问题是Lambda的日志抱怨我相信的配置,给我一个错误:等待握手时超时。
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' }
我在AWS中添加了VPC和安全组,但仍然遇到同样的错误。我用尽了如何解决它的想法。
增加lambda函数的超时值。分配更多内存和超时的选项是aws中任何lambda函数的一些设置
我明白了。错误的是,Lambda实际上是在没有建立连接的情况下进入另一个功能。所以我所做的就是我添加了等待连接和其他不应相互干扰的功能。
要了解有关await的更多信息,请访问以下链接:https://javascript.info/async-await