aws ラムダ イベント スキーマを検証する必要があります。検証にはバジウムを使用しました。私は2つの異なるケースを持っています。
- ラムダ関数は、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 のみを実行します。しかし、余分なキーが存在するかどうかを確認する必要があります。
- ラムダ関数は、複数のタイプのイベントをサポートしています。
このような
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" }
- このような問題に最適な scema 検証 npm パッケージはどれですか?
- vandiumはjson 検証に適していますか?