Add steps to prevent duplication and add face to index

If the uploaded photo has passed the basic face detection checks, the next step is to ensure the face has not been stored in our collection already to prevent the same user from signing up multiple times. In this section, you will add a CheckFaceDuplicate step to your state machine by leveraging the FaceSearchFunction AWS Lambda function.

Second state machine diagram
  1. Edit your rider-photo-state-machine.json file to add a new step to the workflow.

    First, add a new state CheckFaceDuplicate following the PhotoDoesNotMeetRequirement state. Then, replace the REPLACE_WITH_FaceSearchFunctionArn with the FaceSearchFunctionArn from the AWS CloudFormation output:

    "CheckFaceDuplicate": {
    	"Type": "Task",
    	"Resource": "REPLACE_WITH_FaceSearchFunctionArn",
    	"ResultPath": null,
    	"End": true,
    	"Catch": [
    			"ErrorEquals": [
    			"ResultPath": "$.errorInfo",
    			"Next": "PhotoDoesNotMeetRequirement"
  2. Find the line in the FaceDetection state that marks it as the End state of the state machine

    "End": true,

    and replace it with

    "Next": "CheckFaceDuplicate",

    This tells AWS Step Functions if the FaceDetection state runs successfully, go on to run the CheckFaceDuplicate state as the next step in the process.

  3. At this point, your rider-photo-state-machine.json file should look like this (the AWS Lambda ARNs are examples):

    (expand to see)
  4. Go back the AWS Step Functions Console, select the RiderPhotoProcessing state machine and click the Edit state machine button

    Edit state machine
  5. Copy-paste the updated JSON definition into the editor, then click Save

    Update state machine definition
  6. An IAM warning will appear suggesting to verify your IAM role’s permissions. Click Save anyway.

    Save state machine definition
  7. Click Start execution.

  8. Test the new state machine with the test input you’ve used before:

    	"userId": "user_a",
    	"s3Key": "1_happy_face.jpg"

    Because we haven’t added the step yet to index the face in the photo into the Rekognition collection, the CheckFaceDuplicate step will always succeed at this point.