Deploying a Lightweight Face Analytics Tool on AWS with boto3 and Rekognition

In this project, we’re building a small face-analysis tool using Amazon Rekognition. The workflow is simple. You upload an image to an S3 bucket, the script reads the file name, sends it to Rekognition through boto3, and retrieves the details for every detected face. We extract attributes like age range, gender, and dominant emotion. Then Python writes those results directly onto the image using a red marker, similar to the sample you saw. It is a lightweight setup that gives you a clear and instant look at what Rekognition can detect.

Steps We Followed to Run the Project

  1. Creating an Amazon S3 Bucket
  2. Uploading Images to the S3 Bucket
  3. Installing and Configuring the AWS Command Line Interface (CLI)
  4. Importing Libraries
  5. Adding the Face Details Function
  6. Adding the Main Function
  7. Running Your Python File

Services Used

Amazon S3 Used to store the input images.

Amazon Rekognition Used to analyse the images and extract face attributes.

AWS CLI Used to interact with AWS services through the command line.

Before Running the Code

Create a new IAM user with the AmazonRekognitionFullAccess policy. and the following custome-managed policy to restict access of the use to only the targeted bucket. less permissions better for security.
Here it is in **proper code-block markdown for your blog**, clean and ready to paste:


{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowListBucket",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::YOUR-BUCET-NAME"
    },
    {
      "Sid": "AllowObjectReadWrite",
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:PutObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::YOUR-BUCET-NAME/*"
    }
  ]
}

Then generate an Access Key and Secret Access Key. You will provide these credentials when configuring AWS CLI.

To check whether AWS CLI is installed correctly, run:

aws --version

To configure the AWS CLI, run:

aws configure

Best Practices When Using Access Keys

  • Never store your access key in plain text, in a repository, or inside code.
  • Disable or delete any unused access keys.
  • Apply least-privilege permissions.
  • Rotate access keys regularly.

Python Code Explanation

The analyze_faces function accepts an S3 bucket and object key, calls detect_faces with Attributes=['ALL'], and prints an easy-to-read summary for each person Rekognition detects, including estimated age range, gender, and dominant emotion.

After collecting the attributes, the script downloads the same image from S3, renders it with Matplotlib, and overlays a red bounding box along with a compact label (gender, age range, dominant emotion).

Running main() will analyze the default YOUR-IMAGE-NAME object in the YOUR-S3-BUCKET-KEY bucket. Make sure you replace these placeholders with your actual image name and bucket name. Also confirm that AWS credentials are configured in your terminal so boto3 can access both S3 and Rekognition.

Code Repository

The code in github on this link

Ali Alrahbe
Ali Alrahbe

Hi, 👋 I'm Ali Alrahbe, a cybersecurity professional passionate about building cloud infrastructures that are both secure and resilient.

I got my start in tech on the front lines of IT support. That experience didn't just teach me how to solve complex problems—it showed me that proactive security is the bedrock of any successful digital system. That realization drove me to specialize in cloud security.
I'm AWS Certified Solutions Architect Associate, I hold a Bachelor's degree in computer systems engineering and currently pursuing a Master's in Cybersecurity in Berlin, focusing on Cloud Security, DevSecOps, and Infrastructure as Code (IaC).

On my website, Corefortify.com, I document my journey, share hands-on projects, and break down complex security concepts in the evolving world of cloud technology.

Feel free to connect with me on LinkedIn!

Articles: 14