Can AWS Lambda reach / interact with S / FTP?

I wrote some basic js to just list FTP files, but I get:

"The process is completed before the request is completed"

Is it because Lambda cannot interact with FTP?

I am using jsftp btw.

Here is my setup:

  • I use Serverless to create a project
  • For my lambda, I used nodejs and I use JSFTP to work with ftp files.

My code is:

// Require Serverless ENV vars var ServerlessHelpers = require('serverless-helpers-js').loadEnv(); // Require Logic var lib = require('../lib'); // Lambda Handler module.exports.handler = function (event, context) { lib.respond(event, function (error, response) { return context.done(error, response); }); }; 

My ftp lambda code:

 var JSFtp = require("jsftp"); module.exports.respond = function (event, cb) { var ftp = new JSFtp({ host: "host", user: "user", password: "password" }); ftp.auth(ftp.user, ftp.password, function(err, res) { if (err) console.log(err); else console.log(res); ftp.ls(".", function (err, res) { var results = []; res.forEach(function (file) { results.push(file.name); }); ftp.raw.quit(); return cb(null, results.length); }) }); }; 

I have added some console.log () throughout, and it seems like he was suffocating as soon as he tried to execute ftp.auth.

The output that I see in cloud mode:

 START RequestId: __ID__ Version: $LATEST END RequestId: __ID__ REPORT RequestId: __ID__ Duration: 526.46 ms Billed Duration: 600 ms Memory Size: 1024 MB Max Memory Used: 33 MB Process exited before completing request 

So it looks like he just choked somewhere ...

+5
source share
3 answers

In short, ftp will not work with lambda, as they use ephemeral ports.

sftp will work well with lambda. I tested using java code through jsch without problems; I cannot see how it will not work with any js sftp lib.

+3
source

Now you can test. Make sure ur timeout is set long enough and you call context.succeed () when the process ends

 function __main__(event, context) { var JSFtp = require("jsftp"); var ftp = new JSFtp({ host: "speedtest.tele2.net", port: 21, // defaults to 21 }); ftp.ls(".", function(err, res) { var results = []; res.forEach(function(file) { results.push(file.name); }); context.succeed(results); }); }; 
+3
source

By default, Lambda functions only require 3 seconds. If this takes longer, you will receive the error message that you see.

You can set a timeout for anything, up to 5 minutes. To change it using the aws CLI, run:

 aws lambda update-function-configuration --function-name my-lambda-function --timeout 300 
+1
source

Source: https://habr.com/ru/post/1238651/


All Articles