Create a Stream Processor

In this step, you will create a stream processor, analyze video from Amazon Kinesis Video Streams with Amazon Rekognition Video, and handle the results using Amazon Kinesis Data Streams.

Creating a stream in Amazon Kinesis Data Streams

Create a stream of Amazon Kinesis Data Streams to receive the results from the stream processor of Amazon Rekognition Video.

  • Open Amazon Kinesis Data Streams console
  • Select Data streams from the menu on the left and click on Create data stream on the right
  • Enter the following settings and click Create Data Stream
    • Data stream name: kvs-workshop-data-stream
    • Number of open shards: 1

Wait for the status of the stream to change from Creating to Active.

After the stream is crated, copy the ARN value of the stream’s details.

Run the following command to set the copied ARN in an environment variable.

export DATA_ARN="ARN of the data stream (e.g. arn:aws:kinesis:your-region:012345678901:stream/kvs-workshop-data-stream)"

Creating an IAM Role

Create an IAM role to run the stream processor.

  • Open IAM Roles Consle
  • Select Roles from the menu on the left and click on Create role on the top
  • Select the following and click Next: Permissions
    • Select type of trusted entity: AWS Services
    • Choose a use case: Rekognition
  • Click on the Next: Tag
  • Click on Next: Review
  • Enter the following and click Create role
    • Role name: kvs-workshop-rekognition-role

Then click on the created kvs-workshop-rekognition-role from the list of roles.

Copy the role ARN in the overview and run the following command to set the copied ARN in the environment variable.

export ROLE_ARN="IAM Role ARN (e.g.: arn:aws:iam::012345678901:role/kvs-workshop-rekognition-role)"

Attach a policy to the IAM role you have created.

  • Click the Attach policies on the Permissions tab
  • Search for kinesis in the policy filter and check the box to the left of AmazonKinesisFullAccess
  • Click the Attach policy at the bottom of the screen

Creating a stream processor.

Once you have created a collection, a data stream, and an IAM role, you can create a stream processor for the collection.

First, copy the ARN for the Amazon Kinesis Video Streams stream.

  • Open Amazon Kinesis Video Streams Console
  • Click on the Video streams in the left menu > Click on kvs-workshop-stream in the list of streams
  • Copy the value of the video stream ARN at the bottom of the page

Execute the following command from the terminal and set the copied ARN to the environment variable.

export VIDEO_ARN="ARN of video stream (e.g. arn:aws:kinesisvideo:your-region:012345678901:stream/kvs-workshop-stream/1587989123456)"

Then create the stream processor by running the following command.

aws rekognition create-stream-processor \
  --input "KinesisVideoStream={Arn=$VIDEO_ARN}" \
  --name kvs-workshop-processor \
  --settings "FaceSearch={CollectionId=$COLLECTION_ID,FaceMatchThreshold=50.0}" \
  --role-arn $ROLE_ARN \
  --stream-processor-output "KinesisDataStream={Arn=$DATA_ARN}"

If you get the result like below, a stream processor is created.

{
    "StreamProcessorArn": "arn:aws:rekognition:your-region:012345678901:streamprocessor/kvs-workshop-processor"
}

Finally, run the following command to start the stream processor you created.

aws rekognition start-stream-processor --name kvs-workshop-processor

Confirming the metrics

Let’s confirm the stream processor you created is working.

First, let’s check that faces are recognized on Amazon Rekognition Video.

  • Open Amazon Rekognition Console
  • Click on the Metrics on the left menu
  • Select the Last 4 hours at the top and make sure the call is successful and faces are detected, as shown below

Amazon Rekognition Metrics

Next, confirm that the recognition results have been sent to Amazon Kinesis Data Streams.

  • Open Amazon Kinesis Data Streams Console
  • Select Data streams from the menu on the left and click kvs-workshop-data-stream
  • Open the Monitoring tab and make sure that data is being put, as shown in the figure below.

Amazon Kinesis Data Streams Metrics

That’s it. You have set up the stream processor. Now, let’s analyze the facial recognition results.