Last active
August 9, 2020 16:58
-
-
Save asanka-x/ed7a6c2f6588b3d2df639782a0d14ab8 to your computer and use it in GitHub Desktop.
AWS fraud detector event prediction using nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
const fraudDetector = new AWS.FraudDetector({ | |
region:'us-east-1' | |
}); | |
let params = { | |
detectorId: 'user_registration_fraud_detector', | |
entities: [ | |
{ | |
entityId: 'unknown', | |
entityType: 'user' | |
} | |
], | |
eventId: 'event-id-1', //provide a unique id here | |
eventTimestamp: new Date().toISOString(), | |
eventTypeName: 'user_registration', | |
eventVariables: { | |
'email': '[email protected]', | |
'ip':'1.2.3.4', | |
'mobile':'94771234567', | |
'method':'email' | |
}, | |
detectorVersionId: '1' | |
}; | |
fraudDetector.getEventPrediction(params, (err, data) => { | |
if (err){ | |
console.log(err, err.stack) | |
}else{ | |
console.log(data); | |
if(data.ruleResults.length > 0 && data.ruleResults[0].outcomes[0] === 'low_risk_outcome'){ | |
console.log('low fraud risk'); | |
//allow registration | |
}else{ | |
console.log('high fraud risk'); | |
//deny registration | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment