Using AWS Step Functions in CFML: Performing the Image Analysis Task
Posted 10 May 2019
It’s taken us a few posts to get to this point, but we’ve now randomly chosen an image on which we’ll perform analysis using AWS Rekognition, a machine vision service. This post introduces no new state types, and focuses on the Lambda code used to perform the image analysis.
The last state in the execution of our workflow was one of two pass states: either setDataForImageOne or setDataForImageTwo. Both of these pass states specified “getImageLabels” as the next step in the workflow. Here’s the definition of the getImageLabels state:
This is a simple task state that finishes up our workflow. The code for the detectLabelsForImage Lambda function is as follows:
Note that the event.s3Bucket and event.s3Key values came from the setDataForImageOne or setDataForImageOne pass states.
If you’d like to know what the MaxLabels and MinConfidence values represent in the params structure, please read the post on detecting labels in an image from my series on working with the Rekognition service from CFML.
The important code in this Lambda function comes at the end, where we invoke the detectLabels() function on the Rekognition service object. This function returns a set of data that we will later return to the caller of our Step Functions workflow. We add the s3Bucket and s3Key values to that data object so our caller will know which image was randomly chosen. That data is then sent back to our caller — the Step Functions workflow.
This task state is the final practical step in this example Step Functions workflow. The question then is: how does a Step Functions workflow know when to finish? How does the result of this Step Functions workflow get back to the thing that invoked this Step Functions workflow execution in the first place?
That’s the subject of the next post.