Face Comparison in Web Apps with AWS Rekognition

Face comparison used to sound like a "hackathon-only" feature. Now? You can plug it into your side project or SaaS in an evening—thanks to tools like AWS Rekognition. Let’s talk about how you can compare faces in images, real use cases, and how to integrate it with a few lines of code. What is Face Comparison? At its core, it answers this: "Does this face match another face?" Behind the scenes, Rekognition scans both images, detects faces, and returns a similarity score. Here's the CompareFaces API for that. Common Use Cases You’ll see this in real-world projects like: eKYC (Know Your Customer): Compare a selfie with a government ID photo. Duplicate Account Detection: Flag same-person signups with different emails. Event Check-ins: Snap a selfie, match with registered photo. Visitor Validation: Match new visitors to previously stored images. Internal Tools: Audit employee check-ins with face scan verification. All of these can be implemented by storing the original photo once in S3, and comparing it with real-time uploads whenever needed. Pricing? Rekognition pricing is pay-as-you-go, and here's a quick breakdown for Group 1 APIs like CompareFaces and IndexFaces: Images Processed Price/Image First 1 million $0.001 Next 4 million $0.0008 Next 30 million $0.0006 Over 35 million $0.0004 ⚡ That’s less than a cent per comparison. And you get free tier access to test things out. Code in Action (Node.js + S3) Let’s say you’ve got two images in an S3 bucket: bezos_original.jpeg – stored reference image bezos_current.jpeg – new upload to compare Here’s the minimal setup: var AWS = require("aws-sdk"); const bucket = "fd-23"; const photo_source = "face-recognition/bezos_current.jpeg"; const photo_target = "face-recognition/bezos_original.jpeg"; var credentials = new AWS.SharedIniFileCredentials({ profile: "default" }); AWS.config.credentials = credentials; AWS.config.update({ region: "ap-south-1" }); const client = new AWS.Rekognition(); const params = { SourceImage: { S3Object: { Bucket: bucket, Name: photo_source }, }, TargetImage: { S3Object: { Bucket: bucket, Name: photo_target }, }, SimilarityThreshold: 70, }; client.compareFaces(params, function (err, response) { if (err) { console.log("error : ", err, err.stack); } else { response.FaceMatches.forEach((data) => { let position = data.Face.BoundingBox; let similarity = data.Similarity; console.log( `The face at: ${position.Left}, ${position.Top} matches with ${similarity.toFixed(2)}% confidence` ); }); } }); Output: Got not authorized Error? If you see something like: is not authorized to perform: rekognition:CompareFaces Then your IAM user needs the correct permissions. Attach the policy: Should You Use Face Indexing? If you want to compare future images to previously added ones, then indexing is your friend. Use IndexFaces to add a face to a collection and search it later. TL;DR Face comparison is easy with AWS Rekognition. Use cases? From eKYC to event apps. Pricing is scalable and dev-friendly. Store one reference image in S3 and reuse it for all comparisons. IAM permissions matter—set them right. Want to try it out? Check the Rekognition docs, throw two images in S3, and you're good to go. Got any use case in mind for your own project? Let me know in the comments. I’ve been actively working on a super-convenient tool called LiveAPI. LiveAPI helps you get all your backend APIs documented in a few minutes With LiveAPI, you can quickly generate interactive API documentation that allows users to execute APIs directly from the browser. If you’re tired of manually creating docs for your APIs, this tool might just make your life easier.

Apr 21, 2025 - 19:32
 0
Face Comparison in Web Apps with AWS Rekognition

Face comparison used to sound like a "hackathon-only" feature. Now? You can plug it into your side project or SaaS in an evening—thanks to tools like AWS Rekognition.

Let’s talk about how you can compare faces in images, real use cases, and how to integrate it with a few lines of code.

What is Face Comparison?

At its core, it answers this:

"Does this face match another face?"

Behind the scenes, Rekognition scans both images, detects faces, and returns a similarity score.

Here's the CompareFaces API for that.

Common Use Cases

You’ll see this in real-world projects like:

  • eKYC (Know Your Customer): Compare a selfie with a government ID photo.
  • Duplicate Account Detection: Flag same-person signups with different emails.
  • Event Check-ins: Snap a selfie, match with registered photo.
  • Visitor Validation: Match new visitors to previously stored images.
  • Internal Tools: Audit employee check-ins with face scan verification.

All of these can be implemented by storing the original photo once in S3, and comparing it with real-time uploads whenever needed.

Pricing?

Rekognition pricing is pay-as-you-go, and here's a quick breakdown for Group 1 APIs like CompareFaces and IndexFaces:

Images Processed Price/Image
First 1 million $0.001
Next 4 million $0.0008
Next 30 million $0.0006
Over 35 million $0.0004

⚡ That’s less than a cent per comparison.

And you get free tier access to test things out.

Code in Action (Node.js + S3)

Let’s say you’ve got two images in an S3 bucket:

  • bezos_original.jpeg – stored reference image
  • bezos_current.jpeg – new upload to compare

Here’s the minimal setup:

var AWS = require("aws-sdk");
const bucket = "fd-23";
const photo_source = "face-recognition/bezos_current.jpeg";
const photo_target = "face-recognition/bezos_original.jpeg";

var credentials = new AWS.SharedIniFileCredentials({ profile: "default" });
AWS.config.credentials = credentials;
AWS.config.update({ region: "ap-south-1" });

const client = new AWS.Rekognition();
const params = {
  SourceImage: {
    S3Object: { Bucket: bucket, Name: photo_source },
  },
  TargetImage: {
    S3Object: { Bucket: bucket, Name: photo_target },
  },
  SimilarityThreshold: 70,
};

client.compareFaces(params, function (err, response) {
  if (err) {
    console.log("error : ", err, err.stack);
  } else {
    response.FaceMatches.forEach((data) => {
      let position = data.Face.BoundingBox;
      let similarity = data.Similarity;
      console.log(
        `The face at: ${position.Left}, ${position.Top} matches with ${similarity.toFixed(2)}% confidence`
      );
    });
  }
});

Output:

Image description

Got not authorized Error?

If you see something like:

is not authorized to perform: rekognition:CompareFaces

Then your IAM user needs the correct permissions.

Attach the policy:

Image description

Should You Use Face Indexing?

If you want to compare future images to previously added ones, then indexing is your friend.

Use IndexFaces to add a face to a collection and search it later.

TL;DR

  • Face comparison is easy with AWS Rekognition.
  • Use cases? From eKYC to event apps.
  • Pricing is scalable and dev-friendly.
  • Store one reference image in S3 and reuse it for all comparisons.
  • IAM permissions matter—set them right.

Want to try it out?

Check the Rekognition docs, throw two images in S3, and you're good to go.

Got any use case in mind for your own project? Let me know in the comments.

I’ve been actively working on a super-convenient tool called LiveAPI.

LiveAPI helps you get all your backend APIs documented in a few minutes

With LiveAPI, you can quickly generate interactive API documentation that allows users to execute APIs directly from the browser.

Image description

If you’re tired of manually creating docs for your APIs, this tool might just make your life easier.