Editor NodeJS Library usage in lambda

Editor NodeJS Library usage in lambda

naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

Hi,

Good day.

I've setup the nodejs editor to have a look at server side processing. Cool feature, and definitely worth the purchase. The express app runs fine and I was reading into porting it to AWS Lambda. But I have not been successful. I've tried many things online. I eventually get it to return results but the results are not paginated. I think the request must be modified by API Gateway somehow.

Resources I've tried:
https://claudiajs.com/tutorials/serverless-express.html
https://github.com/awslabs/aws-serverless-express

Has anyone got the nodejs editor library working on AWS Lambda? Thanks.

Regards.
Jarrett

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    I've not tried it on AWS Lambda, but assuming you can POST variables to it, there shouldn't be a problem. How are you parsing the body parameters at the moment? And can you print them out in your controller?

    Allan

  • naspersgaspnaspersgasp Posts: 53Questions: 14Answers: 1

    Hi,

    Thanks for the reply, led me to check the req.body and it is empty for some reason when porting to lambda. Will spend some time to figure that out and get back to you.

    Regards.
    JJ

  • gehornegehorne Posts: 10Questions: 2Answers: 1

    Also looking at doing this same thing. If anyone has information on putting this in place, would love to see the details. If I get it working, I'll do the same.

    Have fun

    GEH

  • aChinchillaaChinchilla Posts: 9Questions: 3Answers: 0

    Has anyone been able to receive data back in the req body with lambda?

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    It isn't something I've tried I'm afraid. Can you access POST parameters in AWS lambda normally? Are they available on req.body or somewhere else?

    Allan

  • yildiztuyildiztu Posts: 1Questions: 0Answers: 0

    I have just recently managed to run "datatables" using an AWS Lambda function. It just works. In addition, you need to install "serverless-http". I am still testing other features. I am using AWS Cloud9 and publishing to an AWS Lambda function.

    $ npm install serverless-http

    // An example index.js file:
    // AWS Lambda
    let db = require('./db');
    let express = require('express');
    let serverless = require('serverless-http')
    
    let {
        Editor,
        Field,
        Validate,
        Format,
        Options
    } = require("datatables.net-editor-server");
    
    let app = express();
    
    app.get('/',  async (req, res) => {
        let editor = new Editor(db, 'datatables_demo').fields(
            new Field('first_name').validator(Validate.notEmpty()),
            new Field('last_name').validator(Validate.notEmpty()),
            new Field('position'),
            new Field('office'),
            new Field('extn'),
            new Field('age')
                .validator(Validate.numeric())
                .setFormatter(Format.ifEmpty(null)),
            new Field('salary')
                .validator(Validate.numeric())
                .setFormatter(Format.ifEmpty(null)),
            new Field('start_date')
                .validator(
                    Validate.dateFormat(
                        'YYYY-MM-DD',
                        null,
                        new Validate.Options({
                            message: 'Please enter a date in the format yyyy-mm-dd'
                        })
                    )
                )
                .getFormatter(Format.sqlDateToFormat('YYYY-MM-DD'))
                .setFormatter(Format.formatToSqlDate('YYYY-MM-DD'))
        );
    
            await editor.process(req.body);
        res.json(editor.data());
    });
    
    module.exports.handler = serverless(app)
    
  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    Awesome - thanks for posting that!

    Allan

Sign In or Register to comment.