Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can AWS Lambda reach/interact with S/FTP?

I wrote some basic js to just list the files of a FTP but I get:

"Process exited before completing request"

Is that because Lambda can't interact with FTP?

I'm using jsftp btw.

Here's my setup:

  • I use Serverless to create the project
  • For my lambda, I used nodejs and I'm using JSFTP to deal with the ftp stuff.

My code:

// 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 added some console.log() all over the place and it seems like it choked once it tried to ftp.auth.

The output I see in cloud watch:

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 it just choked somewhere...

like image 273
iCodeLikeImDrunk Avatar asked Dec 18 '15 16:12

iCodeLikeImDrunk


People also ask

Can Lambda Mount EFS?

Lambda integrates with Amazon Elastic File System (Amazon EFS) to support secure, shared file system access for Lambda applications. You can configure functions to mount a file system during initialization with the NFS protocol over the local network within a VPC.

When should AWS Lambda not be used?

You do not want to use Lambda for long-running workloads because it runs instances/functions for up to 15 minutes at a time. It limits concurrent function executions to 1,000. AWS Lambda bills can quickly run through your budget if you are unsure how to optimize AWS costs.

Can Lambda mount EBS?

Lambda can accomodate with all the services provided by AWS. EBS being one of them and it has all the above said features.

What are the restrictions applied to the AWS Lambda function code?

AWS Lambda has the following limitationsThe disk space (ephemeral) is limited to 512 MB. The default deployment package size is 50 MB. The memory range is from 128 to 3008 MB. The maximum execution timeout for a function is 15 minutes*.


1 Answers

in short, ftp will not work with lambda since they use ephemeral ports.

sftp will work nicely with lambda. i tested using java code via jsch with no issues; tho i cant see how it wouldnt work with any js sftp lib.

like image 117
iCodeLikeImDrunk Avatar answered Oct 02 '22 13:10

iCodeLikeImDrunk