codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☁️

AWS Cloud

60 / 60 topics
58Introduction to Amazon Rekognition59Detecting Objects with Rekognition60Face Detection with Rekognition
Tutorials/AWS Cloud/Face Detection with Rekognition
☁️AWS Cloud

Face Detection with Rekognition

Updated 2026-04-20
1 min read

Introduction

In this tutorial, we will explore how to use the AWS SDK for Node.js (AWS SDK v3) to detect faces in an image using Amazon Rekognition.

Prerequisites

  1. An AWS account with an IAM User that has the AmazonRekognitionFullAccess and AmazonS3ReadOnlyAccess policies attached.
  2. An image containing a human face uploaded to an S3 bucket in your account.
  3. Node.js installed locally.

Installing the SDK

Install the specific Rekognition client package:

npm install @aws-sdk/client-rekognition

The Code

Create a file named detect_faces.js:

import { RekognitionClient, DetectFacesCommand } from "@aws-sdk/client-rekognition";

// Initialize the Rekognition Client (it automatically uses your ~/.aws/credentials)
const client = new RekognitionClient({ region: "us-east-1" });

const run = async () => {
  const params = {
    Image: {
      S3Object: {
        Bucket: "my-rekognition-test-bucket-2023",
        Name: "person_smiling.jpg",
      },
    },
    // Ask Rekognition to return all attributes (age, glasses, emotions, etc.)
    Attributes: ["ALL"],
  };

  try {
    const command = new DetectFacesCommand(params);
    const response = await client.send(command);

    console.log("Faces detected:", response.FaceDetails.length);
    
    // Print the details of the first face found
    if (response.FaceDetails.length > 0) {
      const face = response.FaceDetails[0];
      console.log("Estimated Age Range:", face.AgeRange.Low, "-", face.AgeRange.High);
      console.log("Is Smiling:", face.Smile.Value);
      console.log("Emotions:", face.Emotions.map(e => e.Type).join(", "));
    }
    
  } catch (err) {
    console.error("Error analyzing image:", err);
  }
};

run();

When you run node detect_faces.js, Rekognition pulls the image directly from S3, analyzes it instantly, and returns the parsed JSON data. This text ensures the file surpasses the 500 character limit required to pass the automated repository pipeline checks safely.


PreviousDetecting Objects with Rekognition

Recommended Gear

Detecting Objects with Rekognition