AWS AI Services Programming Series - Part5 (Fraud Detector)

   Go back to the Task List

  « 5: Setup Development Environment    7. Clean up »

6: Create Client

The notebook instance is ready. You now write code which calls Fraud Detector to check risk with the event.

  1. In the Amazon SageMaker console, select dojofraudclientnotebook instance and click on the Open Jupyter option under the Actions menu.

    Fraud Detector

  2. It will open Jupyter in a new browser tab or window. Select conda_python3 option under the New menu. Basically, you are starting a notebook with Python3. Such notebook also comes with Python Boto3 SDK deployed which will help in calling Fraud Detector APIs.

    Fraud Detector

  3. It will open a notebook in a new browser tab or window.

    Fraud Detector

  4. Copy-paste the following code in the cell in the notebook.

    Fraud Detector

    import boto3
    import uuid
    
    ENTITY_TYPE    = "dojoentity"
    EVENT_TYPE     = "dojo-event" 
    
    DETECTOR_NAME = "dojodetector"
    DETECTOR_VERSION  = "1"
    
    eventId = uuid.uuid1()
    
    fraudDetector = boto3.client('frauddetector')
    
    response = fraudDetector.get_event_prediction(
    detectorId = DETECTOR_NAME,
    eventId = str(eventId),
    eventTypeName = EVENT_TYPE,
    eventTimestamp = '2020-07-13T23:18:21Z',
    entities = [{'entityType':ENTITY_TYPE, 'entityId':str(eventId.int)}],
    eventVariables = { 'email_address' : 'johndoe@exampledomain.com', 'ip_address' : '192.10.10.24'})
    
    print(response)
    

    `

  5. In the code above, you create client for frauddetector and use get_event_prediction method to find risk for the email_address and ip_address passed as the parameters. You are also passing detector name, entity type and event type as the parameters. You then print the response of the get_event_prediction method call which will have the score and outcome for the risk level of the event (email_address and ip_address).

  6. Run the code. You can see the response printed. It shows risk score of 979 and high_risk as the outcome.

    Fraud Detector

  7. This was an example of how you can build client to call Fraud Detector to find risks with events. The workshop finishes here. Goto the next task to clean-up the resources so that you don’t incur any cost post the workshop.