Building an automated serverless facial analysis system.
Journey: 📊 Community Builder 📊
Subject matter: Building on AWS
Task: Building an automated serverless facial analysis system.
This project is about Performance, Availability, and receiving real-time notifications when new analysis is performed.
Using the 6 Pillars of the AWS Well-Architected Framework, Performance Efficiency and Sustainability will be achieved in this build.
I will be setting up a Serverless Machine Learning service to analyse new image uploads and then perform real-time notifications to the Administrator of its findings.
Credit: This serverless architecture was created using some guidance from Edithcherotich on Medium Here.
What did I use to build this environment?
- Amazon S3
- AWS Lambda
- Amazon Rekognition
- Amazon DynamoDB
- Amazon SNS
- AWS IAM
- Amazon CloudWatch
What is built?
- A new S3 bucket which triggers a Lambda Function
- Amazon Rekognition is used to detect faces in newly uploaded images
- An SNS Topic to receive calls for email distribution
- An SNS Subscription to the new Topic
- A DynamoDB Table for Amazon Rekognition to populate data into if a face is detected
- An SNS trigger to notify an Admin if a face is detected, confirming the expected gender and age
This task involved using Amazon Rekognition to analyse new images that are uploaded to an S3 bucket. AWS Lambda triggers the analysis. If a face is detected by Amazon Rekognition, it determines the gender and age of the person before then populating it into a DynamoDB table. Lambda then triggers an SNS notification via email to the Account Administrator.
I also used the following AWS documentation:
https://docs.aws.amazon.com/sns/latest/dg/sns-getting-started.html
https://docs.aws.amazon.com/sns/latest/dg/sns-create-topic.html
https://docs.aws.amazon.com/sns/latest/dg/sns-create-subscribe-endpoint-to-topic.html
Once I had configured all of the areas, I uploaded a photo of a person into my S3 bucket with the titles ‘celebrating.jpg’ and ‘professional.jpg’ so as not to show gender bias. AWS Lambda triggered off the upload and Amazon Rekognition confirmed a face was present, identified the likely gender and age, and sent a real-time notification to my mailbox.
As a further test, I then uploaded a photo of ‘coffee.jpg’ to my S3 bucket and did not receive any email.
When checking the CloudWatch logs, I identified an error that ‘gender could not be defined’, which is expected behaviour. If we wanted to take the code further, error handling could be introduced to send an email notification of a non-human image detected.
Some of the highlights…
Amazon S3:
AWS Lambda:
S3 images uploaded:
DynamoDB table populated:
CloudWatch:
SNS:
SNS Subscription:
Email notification:
Additional test with an image upload of a coffee cup - expected result would be an error and no notification:
CloudWatch logging an error:
I had great difficulty with getting the Lambda Function code to work, but I got there in the end with a lot of trial and error.
I might have to try and find some time to do some Python courseware at some point!
My interpretation of the architecture:
I hope you have enjoyed the article!