3

aws ラムダ イベント スキーマを検証する必要があります。検証にはバジウムを使用しました。私は2つの異なるケースを持っています。

  1. ラムダ関数は、1 種類のイベントのみをサポートします。

このような

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');
});

この場合、キーが存在するかどうかにかかわらず、 vandiumは validate のみを実行します。しかし、余分なキーが存在するかどうかを確認する必要があります。

  1. ラムダ関数は、複数のタイプのイベントをサポートしています。

このような

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');
    }

});

この場合、test1 と test2 のイベントは異なります。このような

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

test2{"学校名":"threni","先生":"abcd" }

  1. このような問題に最適な scema 検証 npm パッケージはどれですか?
  2. vandiumはjson 検証に適していますか?
4

2 に答える 2

1

ajvを見ましたか?JSONスキーマを使用したデータの検証のように

于 2016-09-05T10:40:36.197 に答える