Skip to content

Image Text/Face recognition with AWS Rekognition👀

🔗AWS Rekognition

What is AWS Rekognition?

Rekognition is a AWS service that provides deep learning visual analysis for your images. Rekognition is very easy to integrate into your application by providing an image or video to the AWS Rekognition API. The service will identify some following: objects, people, text, scenes, and activities. "Amazon Rekognition also provides highly accurate facial analysis and facial recognition. You can detect, analyze, and compare faces for a wide variety of use cases, including user verification, cataloging, people counting, and public safety." - AWS Official Docs

🔗Now let's start using AWS Rekognition

Let's start with trying some of their demos to see how AWS Recognition works.

  1. Go to the following link and play with the demos.

🔗Time to get our hands dirty

Warning🚨 :

  1. You need to have an AWS Management Console account.
  2. It will ask you for your credit card info, but YOU won't be charged for what you use in this tutorial since it's part of the FREE TIER.

🔗Setting up our S3 Bucket

  1. Go to Find services and look for S3

Find AWS services 2) Click on CREATE A BUCKET 3) Enter the bucket name as thisdot-rk-YOUR_NAME 4) Click on NEXT twice 5) Uncheck all the boxes to grant public access to the bucket. Click NEXT

Note: I'm making this bucket public, because for the purpose of this tutorial, I'm not worried about security.

S3 public access 6) Click on CREATE BUCKET. 7) Time to upload some images to S3. Click on the bucket you just created. 8) Download this image and save it as thisdot.png. 9) Click on the dropdown from Mange Permissions, and click on Grant public read access to this object(s). Grant public permission AWS 10) Click NEXT 11) On the Storage Class, select Standard, and click NEXT 12) Click UPLOAD

🔗Setting up our Lambda Function

  1. Go to Find services, and look for Lambda

Find service lambda 2) Click on CREATE FUNCTION 3) For Lambda function name, enter thisdot-rk-YOUR_NAME 4) Under Runtime, click on the dropdown, and select Python 3.7. 5) Click on CREATE FUNCTION Create function 6)Scroll down to where it says Function code. You should see something like this: function code 8)Erase everything you see in the editor, and paste the following code in there:

Note: Change the name of the bucket to the bucket name you created thisdot-rk-YOUR_NAME.

The following code is going to help us finding the text inside of the images. Using the .detect_text method.

 import json
 import boto3

 s3 = boto3.resource('s3')
 def lambda_handler(event, context):
  dump = json.loads(json.dumps(event))
  fileName = dump['image']


  res = {
   "textFound": text
  return res

Note: To Learn more about other AWS Boto Rekognition functions, visit this website.

  1. Scroll down to change the BASIC SETTINGS< of the lambda.
  2. Change Memory to 512MB, and Timeout to 2min 30sec. This is to ensure your lambda doesn't timeout when processing images.
  3. Scroll all the way to the top. In the upper right corner, you should see the SAVE button. Click on it.

🔗Setting up our Security Roles Using IAM

  1. Search for the IAM Service (Services IAM)
  2. On the left navigation bar, click on ROLES.
  3. You can select any lambda you have created to give it a specific role. In this tutorial, we will select the following to give it access to AWS Rekognition.


  1. Then click on ATTACH POLICIES
  2. Search for rekognition
  3. Select AmazonRekognitionFUllAccess

AmazonRekognitionFUllAccess 7) Click on ATTACH POLICY Note: You can have multiple policies attached

🔗Time to Test

  1. Go back to your lambda function.
  2. In the top right corner, select the dropdown that says "Select a test event"
  3. Then select "Configure test events"
  4. Give a name to your event
  5. Then enter the following JSON object
           "image": "thisdot.png"

Where "thisdot.png" is the name of your image inside of your S3 bucket.

  1. Click CREATE
  2. On Your top right corner, you will see the TEST button. Click on it.
  3. You should see a green box. Click on expand details.

Click on expand details 9) Take a look at the response object. As you can see, it has found our text inside of the image. Detected Text

🔗Awesome!!!, right?

Now, let's jump to compare faces. Imagine you want to see if one person appears in the same picture. Rekognition can do this. Imagine all the possibilities!

  1. Download these 2 images.

Source Image

Target Image

  1. Upload them to S3, following the steps previously mentioned.

  2. Go back to your lambda, and create a new test, or edit the existing test. Your test will look like this:

         "sourceImage": "source.jpg",
         "targetImage": "target.jpg"
  3. Then, we are going to modify our lambda code to be able to compare faces

     import json
     import boto3
     s3 = boto3.resource('s3')
     def lambda_handler(event, context):
      dump = json.loads(json.dumps(event))
      sourceImage = dump['sourceImage']
      targetImage = dump['targetImage']
      client = boto3.client('rekognition')
      faceComparison= client.compare_faces(
      SourceImage={'S3Object': {'Bucket':bucket,'Name':str(sourceImage)}},
      TargetImage={'S3Object': {'Bucket':bucket,'Name':str(targetImage)}}
      res = {
       "faceRecognition": faceComparison
      return res
  4. Look at the Execution results, and analyze the data.

Tell me what you think about this tutorial on twitter or comment below!

This Dot Labs is a modern web consultancy focused on helping companies realize their digital transformation efforts. For expert architectural guidance, training, or consulting in React, Angular, Vue, Web Components, GraphQL, Node, Bazel, or Polymer, visit []((

This Dot Media is focused on creating an inclusive and educational web for all. We keep you up to date with advancements in the modern web through events, podcasts, and free content. To learn, visit

You might also like


Taming Forms With react-hook-form


Getting Started with RxJS


Semantic HTML: Why it matters and top tips on how to apply it


React.js 17: No New Features and New JSX Transform