Amazon Rekognition Concepts
Amazon Rekognition Demonstrations
Amazon Rekognition Course Review
The course is part of these learning paths
In this demonstration we will show you how to use the AWSCLI to implement an object and feature detection system that sends an email when certain features are detected within an image. This demonstration will utilise the following command line utilities and AWS services:
- JQ (command-line JSON processor)
- Simple Email Service (SES)
Welcome back. In this lecture, we'll provide a demonstration in which we create a command line script, using the AWSCLI, that performs object and feature detection with Rekognition. Let's now take a quick look at the architecture we're proposing.
Firstly, the design of this demonstration is centered on using the AWSCLI, which is a command line interface that Amazon provides to allow you to integrate and operate for all of the AWS services. We'll use the AWSCLI to upload an image of a car into an S3 bucket. The main part of our demonstration involves using the AWSCLI to make a request to Rekognition to perform object and feature detection on the car image uploaded into S3. We'll take the standard output received when we call the aws rekognition detect-labels command and pipe it through a number of utilities, resulting, finally, in an email being generated and sent via SES, or the Amazon Simple Email Service.
Okay, let's begin setting up the demonstration. So we'll bang back into the terminal. Ensure you're in the demo-CLI directory. Let's list the contents. Next, we'll open this up in Visual Code so that we can have a closer look at the script commands that we'll use. So opening up the AWSCLI.commands file. We'll use the top command, which has already been pre-crafted. Let's zoom in on this command so that we can break it down and discuss each of the individual parts.
So the first part of the command requests AWS to perform object and feature detection using the detect-labels Rekognition command. The standard output received from this command is then piped through a utility called JQ. JQ processes JSON and in this case, we're searching for elements or, more explicitly, name attributes containing the value car or vehicle. We then pipe these results through the next utility which is simply looking for line breaks and replacing them with commas.
Finally, the string result is piped into xargs, which itself forwards into the AWSCLI SES send-email command. Here it is used as the body of an email that is sent via the Simple Email Service. Before run this command, we need to replace the tokens for the from address and the to address. Let's do this now. The from address will be simply email@example.com and the to address will simply be firstname.lastname@example.org. We'll now need to do some setup within the Simple Email Service. So let's jump into the AWS console and do that now.
So bringing up SES, the Simple Email Service console, we'll need to perform domain validation. So clicking on domains, we'll click on the verify new domain. Here, we'll type in democloudinc.com and click the verify this domain button. This represents the domain that we will be sending emails from. We can complete this verification process by clicking the Use Route 53 button, which will automatically place this record within our hosted zone.
Next, let's jump over into Route 53 and see if, indeed, that record has been automatically added into our hosted zone. Here we can see the validation record has indeed been created. Okay, let's go back into the Simple Email Service and see if the domain validation has completed. We'll need to refresh this page a few times, this normally takes about one to two minutes. We'll fast forward the demonstration to the point where the domain has been verified, as it is now.
Okay, the next thing we need to do is verify a new email address for the receiver. So in this case, we'll enter email@example.com This will allow this particular email address to receive emails through the SES service, while this domain is in the sandbox mode. This process generates an email to the address just entered containing a link that needs to be clicked.
Okay. Jumping the demonstration ahead, we've gone to our email client and clicked that link. We can refresh this page and confirm that our email address identity has indeed been verified. Okay, so we're ready now to run our command. Let's jump back into Visual Studio and copy the command.
Okay, let's jump over into the terminal now. The first thing we'll need to do is establish the AWSCLI profile that we'll run our commands under. In this case, I have one called CA for Cloud Academy. Okay, that's now been set. Let's paste the command and run it. The first thing that we'll notice is that this will fail because we haven't uploaded our image into our S3 bucket yet. Here we can see that now. Let's list the contents of the current directory. Within this directory, we have a car.jpg file. Again, we'll use the AWSCLI, in this case, the S3 copy or CP command to upload this car.jpg file into our S3 bucket. Executing this command copies the car.jpg file up into the S3 bucket. This takes a few seconds to complete.
Okay, it looks like it's completed. Let's now do a list on the bucket. We do that by calling AWS S3 LS full list, and then the name of the bucket. Here we can see that indeed our car.jpg file has been uploaded. Before we run the full command, let's jump back into Visual Code. We'll take a look at the project directory and, in particular, look at the car image file. So here, this is the file we've uploaded into S3. Clearly the image is of a car. So we'd expect Rekognition to be able to detect this and send us back the corresponding labels.
Okay, we're ready to rerun the full script. We'll recycle back in our history and rerun the same command. Here we go. Excellent. That has looked like it's worked. We've got a message ID returned from the SES service, which generally implies that the email has been successfully delivered. Jumping into our email client, we can see that we have, indeed, successfully been sent an email. Here we can see the body of our email. This contains the output of our script. In this case, the Rekognition detect labels. Here we can see that it contains car, vehicle, and sports car, together with the confidence values.
Okay, let's jump back into the terminal session and let's break down the command and run the individual parts of it. So, the first part we'll run is the rekognition detect-labels command by itself. This will show us quite clearly the output that it generates. Here we can see that the output is JSON and that it contains labels, one for each of the features that are detected. In this case, I'm highlighting the car, the vehicle, and the sports car features.
Let's now rerun the same command but in this case we'll include the JQ component so that the output of the rekognition detect-labels command is piped into JQ. This will allow us to see what happens. Pasting the command and executing it. Clearly we can see that JQ is performing filtering on the JSON and now only showing the car, the vehicle, and the sports car components.
Again, let's repeat this and rerun the same command but again adding in the next part of the script. And in this case, we'll pipe the output of JQ into the paste utility which will strip any line breaks and replace them with commas. As you can see, our results now are on a single line. And it is this exact string that has been passed in as the content of our body for our email that we send via SES. Okay, let's run the full command again and see what it looks like from the perspective of our mobile device. Pasting the command, executing it, again we get a confirmation back suggesting that the email has been generated and successfully sent.
We'll now jump over to our mobile device and show you what it looks like. Here you can see the end result from the perspective of the mobile device. You can start to see how easy it would be to set up a motion detection system where the end result is an SES, or Simple Email Service, delivered email to your device of choice.
Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.
He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.
Jeremy holds professional certifications for both the AWS and GCP cloud platforms.