Building a Serverless Face Analysis Application on AWS using Terraform

Kevin Tuei
3 min readMay 1, 2024

--

Introduction

Face Recognition and Analysis have various use cases in the world today with one of the main use cases being identity verification especially when it comes to the entry of personnel into secured premises or virtual proctoring of examinations.

Amazon Rekognition assists you in detecting objects, scenes, and faces; extracting text; recognizing celebrities; and identifying inappropriate content in images and videos.

In this challenge by the Cloudforce Sky Community, you will build a serverless face analysis architecture on AWS using Terraform that leverages the Image Recognition Feature of Amazon Rekognition. The Architecture can then be integrated into a Personnel Detection System to identify Staff before they enter the work premises or to verify the identity of candidates before they sit the examination and analyze their faces during the examination process.

Serverless Architecture

Personnel Recognition Architecture on AWS

In the above architecture, a camera is integrated with a microcontroller to control the opening and closing of a door that permits/denies entry to personnel entering an office premise.

The Microcontroller interfaces with the Application Programming Interface (API) gateway that leverages a Lambda Search Function that is connected to Amazon Rekognition leverages the Detect Faces API and entries on a DynamoDB table. The table is populated through a Lambda Indexer Function triggered when the Personnel Photo is uploaded to an S3 Bucket.

The search function returns an HTTP OK (200) when the face of the personnel matches the photo on record or an HTTP NOT FOUND (404) Status when there is no match. This process triggers the microcontroller to either open the door on a 200 response status code or leave it to remain closed on a 400 error.

CloudforceSky Challenge 12 Objectives

The objectives of the Challenge were:

● Create an Amazon S3 bucket with event notifications to trigger the Lambda function.

● Use Amazon Rekognition to detect faces in the uploaded image.

● If the image contains a face, populate the DynamoDB table and trigger Amazon SNS to send email notifications.

Implementation Steps

  1. Design and validate the Infrastructure as Code on Terraform
  2. Deploy the Architecture on AWS successfully.
  3. Review the resources created.
  4. Test the functionality of the Serverless Personnel Rekognition System
DynamoDB items showing detected Faces from Files Uploaded to the S3 Bucket

You can access the Terraform Code for this challenge on my GitHub Repository

Amazon Q explains the index_function.py

Amazon Q Developer provides you with insights on the code along with the ability to refactor and optimize the code for security.

Special appreciation goes to Mehmet Güngören whose 2-part articles on Personnel Recognition with AWS Rekognition strongly influenced my solution to this challenge.

A huge thanks to the Cloudforce Sky Community for coming up with challenges to expand the knowledge and stretch the ability of members.

Conclusion

In this project, you built a Serverless Face Analysis on AWS leveraging an S3 Bucket, a Lambda Function, Amazon Rekognition, DynamoDB, and the Simple Notification Service using Terraform. You can explore more capabilities and use cases of Amazon Rekognition through the Immersion Day AWS Workshop and the features of Amazon Q using the resources provided.

Challenges

At the time of publishing this article, I kept encountering an Internal Server Error on Amazon API Gateway when I passed an Image through to the Lambda Search Function. I am keen on getting a solution and this article on AWS re:Post offers a viable solution.

Resources

--

--

Kevin Tuei

Making the world a better place through technology - Cloud Developer • Certified Educator • ALX Fellow • AWS Community Builder • Atlassian Community Leader