Skip to content

Detector

Source: src/AWS/FraudDetector/Detector.ts

An Amazon Fraud Detector detector — the container that binds an event type to versioned rule sets and models used to evaluate fraud. Creating the detector is cheap; the rules, models, and detector versions that produce predictions are provisioned separately.

Basic Detector

const detector = yield* FraudDetector.Detector("checkout", {
eventTypeName: purchase.name,
});

Detector with an Active Version

const detector = yield* FraudDetector.Detector("checkout", {
eventTypeName: purchase.name,
});
const version = yield* FraudDetector.DetectorVersion("v1", {
detectorId: detector.detectorId,
status: "ACTIVE",
rules: [
{
ruleId: "high_risk",
expression: '$email == "fraud@example.com"',
outcomes: [review.name],
},
],
});

Bind GetEventPrediction in the init phase (providing the GetEventPredictionHttp layer on the Function effect) and score events at runtime against the detector’s ACTIVE version.

// init
const getEventPrediction = yield* FraudDetector.GetEventPrediction(detector);
// runtime
const { ruleResults } = yield* getEventPrediction({
eventId: "order-123",
eventTypeName: "purchase",
eventTimestamp: new Date().toISOString(),
entities: [{ entityType: "customer", entityId: "cust-1" }],
eventVariables: { email: "buyer@example.com", ip: "1.2.3.4" },
});