Personnel Recognition with AWS Rekognition — Part II

Mehmet Güngören
AWS in Plain English
3 min readJan 23, 2023

--

Photo by Agathè Yosefina on Unsplash

In the first article, we finished our S3 bucket for storing personnel photos, keeping rekognition result in DynamoDB table and indexing personnel face in Rekognition collection.

Then comes our next crucial service, providing our API to security systems so that employees can enter the office.

Personnel Search lambda function will do all job for us. Handle HTTP requests from API Gateway then take personnel photo from it, search photo in Rekognition collection if it exists then we will return user information in our DynamoDB as response.

We create an new role for search function . This role need logging permissions, DynamoDB GetItem to get our employee’s information and Rekognition SearchFacesByImage to search image in our collection.

Lets check lambda function source code together.

HTTP Event has an image field which contains our base64 encoded image.
We are passing it to Rekognition search faces by image api, then it will return matched faces id with us. Then we are fetching matched faces details from DynamoDB.

Lets implement our latest resource which is API Gateway.

Firstly create our recognition api, then add an resource path search to it. Our method will be POST . Next, we need to integrate our api gateway with the lambda function. Last part to deploy our api gateway with a stage .

Now it’s time for action after sharing all the code pieces.

Terraform will create 22 different resources in you AWS account.

That all the steps are completed, let’s look at the terraform output.

There are two output one for s3 path to upload our personnel photo, other is api url for searching users by their photo.

🚀 Testing time 🚀

There are many ways to upload photo to S3 bucket but I will use aws-cli to upload my photo.

aws s3 cp Mehmet-GUNGOREN.jpg s3://my-company-personnel-storage-wanted-amoeba/photos/portait/ --metadata x-amz-meta-name=Mehmet,x-amz-meta-surname=Gungoren

You can use many metadata just you need to use them with x-amz-meta-

Lambda successfully catch our upload event and complete Rekognition process, then result on DynamoDB table.

{
"FaceId": "348586d5-c211-42da-91b7-0fff3cf1c884",
"age": "18 - 26",
"bounding_box": {
"Height": 0.35801962018013,
"Left": 0.3011908531188965,
"Top": 0.19286587834358215,
"Width": 0.36411821842193604
},
"bucket": "my-company-personnel-storage-wanted-amoeba",
"emotions": [
"CALM"
],
"gender": "Male",
"has": [
"open eyes"
],
"image_id": "72256c54-6fa4-394a-8c07-51a167ee8bb7",
"key": "photos/portrait/1673-MEHMET-GUNGOREN.jpg",
"object_metadata": {
"name": "Mehmet",
"surname": "Gungoren"
}
}

The final stage is now to simulate the security tools.

(echo -n '{"image": "'; base64 -i IMG_8416.JPG; echo '"}') \
| curl -H "Content-Type: application/json" -d @- \
https://mixuwvafi2.execute-api.us-east-2.amazonaws.com/prod/search

Curl command response.

{"statusCode": 200, "data": [{"name": "Mehmet", "surname": "Gungoren"}]}

Source code is uploaded on my github

Indexed photo and photo used in search.

Cleanup

After you tested and want to avoid further costs. Run

terrafrom destroy -auto-approve

Take away

The fact that different images of the same person provide the same FaceID information as AWS Rekognition is one of the most crucial lessons I want you to take away from this post. The second problem is that S3 Objects’ metadata properties can be used as key-value pairs.

I hope you found this article interesting and useful. ✋

Give this article a round of applause 👏 if it peaked your interest.

More content at PlainEnglish.io.

Sign up for our free weekly newsletter. Follow us on Twitter, LinkedIn, YouTube, and Discord.

Build awareness and adoption for your tech startup with Circuit.

--

--