Face detection on AWS. Ethnus Codemithra article cover.

Build a face detection app on AWS

Neeraj Patel

Neeraj Patel

You can build a working face detection app on AWS with three services. Use an EC2 instance, a private S3 bucket and Amazon Rekognition. The instance uploads a photo to the bucket and calls Rekognition through an IAM role, not a public link. Rekognition prints its result to your terminal. What it costs depends on which AWS free plan your account is on, so read the free plan section before you start. Checked against the official AWS Free Tier and Rekognition pricing pages on 8 September 2026.

How the pieces fit together. Upload the photo: The EC2 terminal uploads a test image to a private S3 bucket.. Assume the role: The instance uses its attached IAM role to get temporary credentials.. Call DetectFaces: Python code calls Rekognition DetectFaces with the S3 object reference.. Read the result: Rekognition returns a FaceDetails JSON array with one entry per face.. Print to terminal: The script prints the face count and attributes on the EC2 terminal.
An EC2 instance uses its IAM role to read a private S3 object and call Rekognition. Nothing needs public access.

What changed since this project first went live

An earlier version of this tutorial from 2020 told readers to make their S3 bucket public. It also used the now retired t2.micro instance type. Both instructions are outdated. AWS buckets and objects block public access by default today. AWS recommends keeping all four Block Public Access settings on (AWS S3 Block Public Access documentation). This rewrite keeps the bucket private throughout and lets an IAM role do the work instead.

The other change is cost. AWS no longer gives every new account 12 months of free services. Read the next section before you create anything.

What free means on AWS today

AWS's current free plan gives new sign-ups up to 200 dollars in credit over six months. New accounts get 100 dollars in credit at once, and can add up to 100 dollars more, for that 200 dollar total. The credits expire after six months, or when they run out, whichever comes first (AWS Free Tier, AWS's July 2025 announcement). Older AWS documentation separately describes an always-free 12-month structure for accounts that predate this change. Check your own account's plan at aws.amazon.com/free rather than assuming which one applies.

Rekognition's own pricing page still advertises 1,000 images a month free for 12 months from account creation. It also lists 1,000 free face vector objects a month and, separately, 1,000 free user vector objects a month (Amazon Rekognition pricing). AWS has not updated that page for the July 2025 change. Treat it as accurate only on the legacy 12-month plan. Do not assume a blanket 12 months of free Rekognition on a new signup.

Current Free Plan-eligible EC2 instance types are T3.micro, T3.small, T4g.micro, T4g.small, C7i-flex.large and M7i-flex.large. Older tutorials mention t2.micro, which is no longer on that list (AWS Free Tier compute).

What free means on AWS today. AWS's current free plan: Up to 200 dollars in credit, expires after 6 months or when credits run out, whichever is first. Some AWS documentation still describes: A 12 month always free structure for eligible services, separate from the newer credit plan. Per the Rekognition pricing page: 1,000 free face vector objects a month, plus 1,000 free user vector objects a month. Free Plan eligible instance types: T3.micro, T3.small, T4g.micro, T4g.small, C7i-flex.large and M7i-flex.large, not t2.micro
Check which plan your account is on at aws.amazon.com/free before you assume a service is free.

Step 1: create your AWS account

Sign in or create an account at the AWS Management Console. AWS asks for a payment card during signup. The free credit and free plan limits mean this project should not draw a charge. Just follow the clean-up step at the end. Note your account's creation date, so you know which free plan row applies to you.

Step 2: pick a region and stay in it

Pick one AWS region and use it for every service in this project. US East (Ohio), region code us-east-2, has three availability zones (AWS Availability Zones documentation). Select it from the region dropdown near your account name in the console before you launch anything.

Step 3: launch a Free Plan-eligible EC2 instance

Go to EC2 in the console and launch an instance with these choices.

  • Amazon Linux as the operating system image.
  • An instance type from the current Free Plan list, such as T3.micro or T4g.micro. Skip t2.micro (AWS Free Tier compute).
  • A new key pair, though you will use EC2 Instance Connect rather than the key file in step 5.
  • A security group that allows SSH so you can fall back to a terminal client if you ever need one.

Launch the instance and wait for its status to show running before you continue.

Step 4: create a scoped IAM role and attach it

An IAM role gives your EC2 instance temporary credentials to call other AWS services. The instance does not need long-lived keys stored on the machine. AWS's current guidance favours a right-sized, least-privilege policy over broad full-access policies (AWS Identity and Access Management). Skip AmazonS3FullAccess and AmazonRekognitionFullAccess. Write a policy scoped to your one bucket and to the rekognition:DetectFaces action instead.

  1. In IAM, go to Roles and create a new role for the EC2 service.
  2. Attach a custom policy that allows s3:GetObject and s3:PutObject on your bucket's ARN, plus rekognition:DetectFaces. Rekognition has no resource-level permissions for that action.
  3. Name the role and create it.
  4. From the EC2 console, select your instance. Choose Actions, then Security, then Modify IAM role. Attach the role you just created.

A role scoped this way still lets your code do its job. A leaked credential or a coding mistake elsewhere cannot reach other buckets or other Rekognition operations.

Step 5: connect with EC2 Instance Connect

Open a browser-based SSH session straight from the EC2 console with EC2 Instance Connect. It needs no separate SSH client, unlike the old PuTTY workflow with its key file conversion step. It costs nothing extra (AWS's EC2 Instance Connect announcement). Select your instance, choose Connect, then the EC2 Instance Connect tab, and choose Connect again. A terminal opens in your browser, already signed in as ec2-user.

Step 6: create a private S3 bucket and upload a test photo

Create an S3 bucket in the same region as your instance. Leave every Block Public Access setting on. New buckets and objects block public access by default. AWS recommends leaving that setting in place (AWS S3 Block Public Access documentation). The bucket does not need to be public. The IAM role from step 4 already grants your instance the access it needs.

On your instance terminal, install the AWS CLI and Python's boto3 library if you have not already. Then upload a test photo with a face in it.

aws s3 cp sample.jpg s3://your-bucket-name/sample.jpg

Use your own bucket name here. The role from step 4 makes this command work without a public bucket or a stored access key.

Step 7: call Rekognition from Python

Amazon Rekognition's DetectFaces operation finds the 100 largest faces in an image. It reads the image straight from an S3 object reference. You never download or expose the file (AWS Rekognition DetectFaces documentation). Save the following as detect_faces.py on your instance and adjust the bucket and photo names.

import boto3

def detect_faces(bucket, photo):
    client = boto3.client('rekognition')
    response = client.detect_faces(
        Image={'S3Object': {'Bucket': bucket, 'Name': photo}},
        Attributes=['ALL']
    )
    print('Detected faces for ' + photo)
    for faceDetail in response['FaceDetails']:
        print('The detected face is between ' +
              str(faceDetail['AgeRange']['Low']) + ' and ' +
              str(faceDetail['AgeRange']['High']) + ' years old')
        print('Confidence: ' + str(faceDetail['Confidence']))
    return len(response['FaceDetails'])

def main():
    bucket = 'your-bucket-name'
    photo = 'sample.jpg'
    face_count = detect_faces(bucket, photo)
    print('Faces detected: ' + str(face_count))

if __name__ == '__main__':
    main()

Run it with python3 detect_faces.py. The response holds a FaceDetails list, one entry per detected face. Each entry carries attributes such as age range and confidence, since the code requests Attributes=['ALL']. Your terminal prints the face count and the attributes for each face found.

Step 8: clean up before you close the terminal

Before you move on, remove everything you created so nothing draws down your credit balance later.

  • Terminate the EC2 instance from Actions, then Instance State, then Terminate.
  • Delete the IAM role you created in step 4.
  • Empty the S3 bucket, then delete the bucket itself.

Do this in the same session, while the steps are fresh, rather than leaving the instance running for later.

Try it yourself: swap the operation

Once DetectFaces works, change one line in the script to call compare_faces or detect_labels instead. Keep the same S3 object and the same IAM role. Compare what each response structure returns before you decide which operation solves your use case. This shows how much of the code above is really about Rekognition's API shape, rather than about faces specifically.

How this fits with Ethnus training

Ethnus and Codemithra run this same project live inside the AWS Cloud Masterclass, a three-hour class. Its named hands-on project builds a facial recognition app. It awards a certificate and badge from Ethnus and NASSCOM FutureSkills after a post-class assessment. The AWS Solutions Architect Associate course teaches the same EC2, S3 and IAM concepts in more depth, plus DynamoDB and CloudWatch. It includes lab access and trainer support. Ethnus reached the milestone of training over 5 lakh students across all its programs (About Ethnus).

Frequently asked questions

Do I need to make my S3 bucket public for Rekognition to read it?

No. Keep Block Public Access on. The IAM role attached to your EC2 instance grants access instead. Rekognition and your code read the object through that role, not through a public bucket policy.

Will this project cost me anything?

It should not, if you stay within your account's free plan and delete the instance, role and bucket straight after. Check whether your account uses the newer credit-based plan or the older 12-month plan before you start.

Why not use t2.micro like older tutorials show?

t2.micro is no longer on the current Free Plan instance list. Use T3.micro, T4g.micro or another instance type from the current list instead.

Do I need PuTTY to connect to the instance?

No. EC2 Instance Connect gives you a browser-based terminal from the console with no separate client, unlike the old PuTTY workflow.

What does DetectFaces actually return?

A FaceDetails list, one entry per face found, up to the 100 largest faces in the image. Each entry can carry attributes such as age range and confidence.

Try this project, then go further with Ethnus Codemithra's AWS Solutions Architect Associate course. If you are new to AWS, start instead with AWS Cloud Practitioner Essentials.

About the Author

Read More

Ethnus User Agreement

I agree to submit my personally identifiable information to Ethnus, who may use it to communicate regarding their events, courses, and other services through various media including phone calls, text messages, email, and social media. I also agree with Ethnus' Privacy Policy and Terms of Service.

I agree with Ethnus sharing my personal data, including email address, with Salesforce family of companies, who may contact me for sales and marketing purposes and as described in Salesforce's Privacy Statement.

Privacy Policy

This Privacy Notice describes how we collect and use your personal information in relation to Ethnus websites, applications, products, services, events, and experiences that reference this Privacy Notice (together, "Ethnus Offerings").

This Privacy Notice does not apply to the "content" processed, stored, or hosted by our customers using Ethnus Offerings in connection with an Ethnus account. This Privacy Notice also does not apply to any products, services, websites, or content that are offered by third parties or have their own privacy notice.

Personal Information We Collect

We collect your personal information in the course of providing Ethnus Offerings to you.

Here are the types of information we gather:

        a) Information You Give Us: We collect any information you provide in relation to Ethnus Offerings. Click here to see examples of information you give us. Example: Name, email, phone, etc.

        b) Automatic Information: We automatically collect certain types of information when you interact with Ethnus Offerings. Example: IP address, location, browser identity, etc.

        c) Information from Other Sources: We might collect information about you from other sources, including service providers, partners, and publicly available sources. Example: marketing analytics, keywords, etc.

How We Use Personal Information

We use your personal information to operate, provide, and improve Ethnus Offerings. Our purposes for using personal information include:

        a) Provide Ethnus Offerings: We may use your personal information to provide and deliver Ethnus Offerings and process transactions related to Ethnus Offerings, including registrations, subscriptions, purchases, and payments.

        b) Measure, Support, and Improve Ethnus Offerings: We use your personal information to measure use of, analyze the performance of, fix errors in, provide support for, improve, and develop Ethnus Offerings.

        c) Recommendations and Personalization: We use your personal information to recommend Ethnus Offerings that might be of interest to you, identify your preferences, and personalize your experience with Ethnus Offerings.

        d) Comply with Legal Obligations: In certain cases, we have a legal obligation to collect, use, or retain your personal information.

        e) Communicate with You: We use your personal information to communicate with you in relation to Ethnus Offerings via different channels (e.g., by phone, email, chat) and to respond to your requests.

        f) Marketing: We use your personal information to market and promote Ethnus Offerings. We might display interest-based ads for Ethnus Offerings.

        g) Purposes for Which We Seek Your Consent: We may also ask for your consent to use your personal information for a specific purpose that we communicate to you.

Cookies

To enable our systems to recognize your browser or device and to provide Ethnus Offerings, we use cookies.

How We Share Personal Information

Information about our customers is an important part of our business and we are not in the business of selling our customers' personal information to others. We share personal information only as described below and with Ethnus Consultancy Services Private Limited, . and its affiliates that are either subject to this Privacy Notice or follow practices at least as protective as those described in this Privacy Notice.

Transactions Involving Third Parties: We make available to you services, software, training, and content provided by third parties for use on or through Ethnus Offerings. You can tell when a third party is involved in your transactions, and we share information related to those transactions with that third party. For example, you can order services, software, and content from sellers using the Authorized Training Partner's marketplace and we provide those sellers information to facilitate your subscription, purchases, or support.

Other than as set out above, you will receive notice when personal information about you might be shared with third parties, and you will have an opportunity to choose not to share the information.

How We Secure Information

        a) We protect the security of your information during transmission to or from websites, applications, products, or services by using encryption protocols and software.

        b) We maintain physical, electronic, and procedural safeguards in connection with the collection, storage, and disclosure of personal information.

Internet Advertising and Third Parties

Ethnus Offerings may include third-party advertising and links to other websites and applications. Third party advertising partners may collect information about you when you interact with their content, advertising, or services. For more information about third-party advertising, including interest-based ads, please read our Interest-Based Ads notice.

Access and Choice

You have choices about the collection and use of your personal information. Many Ethnus Offerings include settings that provide you with options as to how your information is being used. You can choose not to provide certain information, but then you might not be able to take advantage of certain Ethnus Offerings.

        a) Communications: If you do not want to receive promotional messages from us, please unsubscribe or adjust your communication preferences in the emails.

        b) Advertising: If you don't want to see interest-based ads, please adjust your Advertising Preferences.

        c) Browser and Devices: The Help feature on most browsers and devices will tell you how to prevent your browser or device from accepting new cookies, how to have the browser notify you when you receive a new cookie, or how to disable cookies altogether.

Children's Personal Information

We don't provide Ethnus Offerings for purchase by children. If you're under 18, you may use Ethnus Offerings only with the involvement of a parent or guardian.

Retention of Personal Information

We keep your personal information to enable your continued use of Ethnus Offerings, for as long as it is required in order to fulfill the relevant purposes described in this Privacy Notice, as may be required by law (including for tax and accounting purposes), or as otherwise communicated to you. How long we retain specific personal information varies depending on the purpose for its use, and we may delete your personal information in accordance with applicable law.

Contacts, Notices, and Revisions

If you have any concern about privacy at Ethnus, you may also contact us at the addresses below:

Ethnus Consultancy Services Pvt Ltd,

SST Chambers, No.151/17/1 Second Floor, 36th Cross Rd, 5th Block, Jayanagar, Bengaluru, Karnataka 560041

Or, email us at [email protected]

Or call us at: +91 - 8929 334 324

You will find the updated contact information on our website: www.ethnus.com/contact/

If you interact with Ethnus Offerings on behalf of or through your organization, then your personal information may also be subject to your organization's privacy practices, and you should direct privacy inquiries to your organization.

Our business changes constantly, and our Privacy Notice may also change. You should check our website frequently to see recent changes. You can see the date on which the latest version of this Privacy Notice was posted. Unless stated otherwise, our current Privacy Notice applies to all personal information we have about you and your account. We stand behind the promises we make, however, and will never materially change our policies and practices to make them less protective of personal information collected in the past without informing affected customers and giving them a choice.

Terms & Conditions

This Privacy and Security Policy is provided for the benefit of customers and clients of Ethnus Consultancy Services Private Limited. ("Ethnus") as well as other consumers and parties who use Ethnus and/or its website(s), particularly codemithra.com ("Website", "www.codemithra.com", "Codemithra" or "Ethnus Codemithra"), and/or applications ("Apps") (collectively, "Ethnus Services" or "Ethnus Platform").

Since Ethnus serves several different audiences, customers find it helpful to read the Terms of Use that apply specifically to them based upon the purpose for which they use Ethnus. For this reason, we link to three separate agreements below for employer customers, job seeker customers, and staffing customers, respectively.

For your convenience, we define each of these audiences that Ethnus serves as follows:

"Employer Customer" means an entity using Ethnus Services that is seeking to hire an individual as an employee and/or independent contractor to be employed by it directly.

"Job Seeker Customer" means an individual using Ethnus Services who is seeking to be employed as an employee or independent contractor by an employer.

"Staffing Customer" means a staffing company using Ethnus Services that provides staffing services to their own Staffing Clients.

So long as your use of the Ethnus website and services remains within the scope of the particular audience or customer for which you began using Ethnus (e.g. a job seeker does not use Ethnus as an employer, or an employer does not use Ethnus as a job seeker), the complete Terms of Use applicable to your use of the Ethnus website and services is contained within the applicable Terms of Use linked below.

Employer Terms of Use

The following Terms of Use apply to any Ethnus Employer Customer seeking to hire employees or independent contractors for its own business. If you seek to find employees or independent contractors for the benefit of your clients (and not yourself), you need to review the Terms of Use specifically for our Ethnus Staffing Customers accessible at www.Codemithra.com/terms/staffing.

Ethnus, Inc. ("Ethnus") provides online services through which employers and staffing companies seeking employees and independent contractors can efficiently and effectively review and interview candidates. Ethnus provides these services and its suite of features and products through its Apps and Website (collectively, "Ethnus Services") subject to these terms of use ("Terms of Use") and the agreements incorporated herein.

Your privacy is very important to us. We designed our accompanying Privacy and Security Policy to provide important disclosures about how your information will be used by Ethnus in providing you Ethnus Services. These Terms of Use expressly incorporate our Privacy and Security Policy.

Please read these Terms of Use and our Privacy and Security Policy carefully before using any of the diverse Ethnus Services. By visiting the Website, installing any of the Apps, and/or using any of the Ethnus Services, you shall have affirmed your agreement to these Terms of Use.

1. Definitions

2. Modifications - Will Ethnus ever modify these Terms of Use?

3. Ethnus Services - What are the Ethnus Services?

4. Video Content and Services - How and when do you record videos?

5. Pricing, Payments, and Billing - How and when will I be billed for Ethnus Services?

6. Objectionable Content - What if I find content to be objectionable?

7. Customer Conduct

8. Intellectual Property

9. DMCA Policy

10. Reserved for Future Use

11. Resale of Services

12. Indemnification

13. Disclaimer of Warranties

14. Third Party Links and Products

15. Limitations of Liability

16. Exclusions and Limitations

17. General Terms

1. Definitions

"Consumer" means any individual or entity that uses any of the Ethnus Services. Where applicable, the term "Consumer" shall encompass all Ethnus Customers.

"Content" means all material, whether publicly posted or privately transmitted, available on or through any of the Ethnus Services.

"Customer" means, for purposes of this Terms of Use, You, a Job Seeker Customer.

"Customer Content" means any Content uploaded to and/or created through the Ethnus Services by a Ethnus Customer.

"Employer Customer" means an entity using Ethnus Services that is seeking to hire an individual as an employee and/or independent contractor to be employed by it directly.

"GDPR" means the European Union's General Data Protection Regulation.

"Job Seeker Customer" means an individual using Ethnus Services who is seeking to be employed as an employee or independent contractor by an employer.

"Profile Video" means a promotional video created by a Job Seeker Customer to promote themselves as a candidate employee and/or independent contractor. It is not an interview. The Job Seeker Customer completes this independently and on their own.

"Software" means any necessary software used in connection with the Ethnus Services.

"Ethnus Account" means an account associated with a Ethnus Customer who uses or has used Ethnus Services.

"Ethnus Content" means any Content excluding Customer Content and Video Content in which Ethnus does not participate.

"Ethnus Customer" means any person who uses or has used Ethnus Services including, but not limited to, Employer Customers, Job Seeker Customers, and Staffing Customers.

"Ethnus Services" means the suite of features, products and services offered through Ethnus, its Apps, its App Services, the Website, and the Website Services.

"Ethnus Trademarks" means any trademarks, tradenames, logos, and other commercial designs of Ethnus or licensed to Ethnus, whether or not formal registration exists including, but not limited to, "Ethnus."

"Staffing Clients" means third-party employer clients of Staffing Customers.

"Staffing Customer" means a staffing company using Ethnus Services that provides staffing services to their own Staffing Clients.

"Strategic Partners" means those trusted partners that Ethnus employs, engages, or retains to perform functions and/or provide services on its behalf.

"Sub Accounts" means subsidiary accounts created for or by an Employer Customer or Staffing Customer ("such as a consultant group or employer") under its primary account.

"Username" means the valid email address provided by each Ethnus Customer to be used as their username or login identification.

"Video Content" means any video content created by or associated with any Ethnus Customer accessible on and through Ethnus Services including, but not limited to, Profile Videos, Video Questions, Video Interviews, and Welcome Videos.

"Video Interview" means an interview completed through Ethnus Services using a video or "web" camera that an Employer Customer or Staffing Customer requests a Job Seeker Customer complete. A Video Interview may involve a Job Seeker Customer alone or with other participants from an Employer Customer or Staffing Customer. A Video Interview may be pre-recorded by a Job Seeker in response to questions or occur live at which time it would be recorded.

"Video Question" means a question recorded in video and audio that can be sent to potential employee and independent contractor candidates by an Employer Customer or Staffing Customer.

"Website" means all of the content, information and services (in any format whatsoever) accessible through the World Wide Web at the domain name Codemithra.com.

"Website Services" means the services provided by Ethnus through the website at the domain name Codemithra.com, hire.li, and any of our other websites that may be used from time to time