2
aws lambda 이벤트 스키마의 유효성을 검사해야합니다. 나는 유효성 확인을 위해 vandium을 사용했습니다. 두 가지 다른 경우가 있습니다.aws lambda에서 json 스키마 유효성 검사
- 람다 함수는 하나의 이벤트 유형 만 지원합니다. 이 경우이
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만, 확인. 하지만 여분의 키가 있는지 확인해야합니다.
- 람다 함수는 여러 유형의 이벤트를 지원합니다. 이 경우이
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에 대한 이벤트는 diffrent 있습니다. 이
TEST1 같은 { "이름": "안녕하세요", "ID": 100}
TEST2
{ "schoolName": "threni", "선생님": "ABCD"}
- 과 같은 문제에 대해 nce 패키지 중에서 가장 좋은 scema 유효성 검사는 무엇입니까?
- 은 이고, vandium은 json 검증에 적합합니다.