Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json schema validation on aws lambda

i need to validate my aws lambda event schema. i used vandium for validation. i have two diffrent cases.

  1. lambda function support only one type of event.

like this

var vandium = require('vandium');

vandium.validation({
    name: vandium.types.string().required()
});

exports.handler = vandium(function (event, context, callback) {
    console.log('hello: ' + event.name);
    callback(null, 'Hello from Lambda');
});

in this case, vandium only validate , if key is present or not. But i need to check if any extra key is present or not.

  1. lambda function support multiple type of events.

like this

var vandium = require('vandium');

vandium.validation({

    operation: vandium.types.string().required(),
    name: vandium.types.string().required(), });

exports.handler = vandium(function (event, context, callback) {

    const operation = event.operation;
    switch (operation) {
        case 'test1':
            test1(event);
            break;
        case 'test2':
            test2(event);
            break;

        default:
            callback(new Error("Unrecognized operation=" + operation));
            break;
    }


    function test1(event) {
        //console.log('hello: ' + event.name);
        callback(null, 'Hello from Lambda');
    }

    function test2(event) {
        //console.log('hello: ' + event.name);
        callback(null, 'Hello from Lambda');
    }

});

in this case, events for test1 & test2 are diffrent. like this

test1{"name":"hello","id":100 }

test2{"schoolName":"threni","teacher":"abcd" }

  1. Which is the best scema validation npm package for problem like this?
  2. is vandium is suitable for json validation.?
like image 766
Abdul Manaf Avatar asked Sep 07 '25 23:09

Abdul Manaf


1 Answers

have you taken a look at ajv ? like in Validating Data With JSON-Schema

like image 61
adben Avatar answered Sep 10 '25 13:09

adben