Metadata Persistence

Add metadata persistence step

The last step of our image processing workflow is to persist the metadata of the profile photo with the user’s profile.

The ARN of the AWS Lambda function that persists the metadata can be found in the in AWS CloudFormation output PersistMetadataFunctionArn.

  1. Edit your rider-photo-state-machine.json file to add the final persistence step.

    First, add a new state PersistMetadata following the ParallelProcessing state. Also make sure:

    • Replace the REPLACE_WITH_PersistMetadataFunctionArn with the PersistMetadataFunctionArn from the AWS CloudFormation output
    ,
    "PersistMetadata": {
    	"Type": "Task",
    	"Resource": "REPLACE_WITH_PersistMetadataFunctionArn",
    	"ResultPath": null,
    	"End": true
    }	
  2. Find the line in the ParallelProcessing state that marks it as the End state of the state machine.

    "End": true

    and replace it with

    "Next": "PersistMetadata"

    Note: be careful to edit the "End" line at the ParallelProcessing level, not the individual branch level within the parallel state.

    This tells AWS Step Functions if the ParallelProcessing state runs successfully, go on to run the PersistMetadata 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 to the AWS Step Functions Console and click the Edit state machine button to update the RiderPhotoProcessing state machine.

  5. Paste the updated JSON definition and click the refresh button in the preview panel to visualize the changes:

    Update state machine with persistence step
  6. Click the Save button to save the state machine.

  7. Click the Start execution button to test the new state machine with with test input:

    {
    	"userId": "user_a",
    	"s3Bucket": "REPLACE_WITH_YOUR_BUCKET_NAME",
    	"s3Key": "1_happy_face.jpg"
    }	

    If you reference an image that’s already indexed when you were testing the previous state machine, the execution would fail the CheckFaceDuplicate step like this:

    Already indexed face

    You can use the aws rekognition list-faces and aws rekognition delete-faces commands to clean up the previous indexed faces during testing. Or you can upload a different picture to the RiderPhotoS3Bucket and use the s3 key of the new picture to test.