How to Use AWS Rekognition to Identify Celebrities: Complete Tutorial
By Braincuber Team
Published on April 2, 2026
In this article we are going to learn how to make an application using AWS Serverless that lets us identify images of celebrities. We will use AWS Rekognition for AI-based identification. We are going to attach an event to the S3 Bucket so that whenever a file gets uploaded to the bucket, it will invoke a Lambda function that will process the information from the image and save it to the DynamoDB table. This complete tutorial provides a beginner guide with a step by step guide to building a fully serverless AI-powered celebrity recognition application.
What You'll Learn:
- How to set up the Serverless Framework with AWS for celebrity recognition
- How to configure IAM permissions for Rekognition, DynamoDB, and S3
- How to create an S3 trigger that invokes a Lambda function on file upload
- How to call the AWS Rekognition API to identify celebrities in images
- How to store celebrity data (name, gender, emotions) in DynamoDB
- How to deploy and test the complete serverless application
AI-Powered Recognition
AWS Rekognition uses deep learning to identify celebrities, emotions, and facial attributes in images automatically.
Event-Driven Architecture
S3 bucket triggers automatically invoke Lambda functions when images are uploaded, creating a fully automated pipeline.
Serverless Infrastructure
No servers to manage. Lambda, S3, and DynamoDB scale automatically based on usage with pay-per-use pricing.
Structured Data Storage
Celebrity data including names, URLs, gender, and detected emotions are stored in DynamoDB for easy retrieval.
Tech Spec
We are going to use Lambda functions to code our project logic and AWS Rekognition for AI-based image identification of the celebrity.
If we get valid data from the AWS Rekognition API then we are going to store that data in a DynamoDB Table.
All these resources except from the S3 bucket will be created inside the serverless.yml file.
Project Setup
We are going to set up all the things we need in this project step by step. First we will go through the serverless.yml file. Let us get started with the first step.
Our project folder structure should look like this at the end of this tutorial:
celebrity-recognition/
├── serverless.yml
└── src/
└── index.js
How to Set Up the serverless.yml File
We will break down the serverless.yml file into different parts to make it easier to understand.
How to Set Permissions and Configure the Project
service: meta-data-serverless
provider:
name: aws
runtime: nodejs12.x
environment:
DYNAMO_TABLE_NAME: MetaData
BUCKET_NAME: new-bucket-caps2
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- rekognition:RecognizeCelebrities
- s3:Get*
- s3:List*
Resource: "*"
In this code block, we are setting different environment variables and AWS IAM permissions which will be given to our lambda functions. So for our use, we need to write an item to the DynamoDB table, use AWS Rekognition's API to do image identification on the image, and get the file from S3 (all of which we have done in the above code).
Important: Create S3 Bucket First
You will need to create a new public S3 bucket and set the name of that bucket here in place of new-bucket-caps2 as the BUCKET_NAME property. Make sure to create this bucket before you deploy the project.
How to Add a Lambda Function
functions:
processImg:
handler: src/index.handler
events:
- s3:
bucket: ${self:provider.environment.BUCKET_NAME}
event: s3:ObjectCreated:*
existing: true
In the functions block, we are defining a single lambda function which will be invoked when any file is uploaded to the S3 bucket.
As you can see, we are attaching an event to this lambda function on which it will be invoked. s3:ObjectCreated is the event when any file gets uploaded into the S3 bucket.
We are also declaring that this bucket already exists by setting the existing option to true. So make sure that you create this bucket before you deploy the project.
We are also referencing the environment variable for the bucket name which we created in the above section.
How to Add DynamoDB Table Configuration
resources:
Resources:
UsersDynamoDbTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.DYNAMO_TABLE_NAME}
In this block, we are defining our DynamoDB table and its configuration. Any resource we want to create on our AWS account is defined under the resources block in the serverless.yml file. Here we are defining things like table attributes, key schema, and how much provisioned throughput capacity we want to give our table.
For the table attributes, all other attributes will be dynamically added to the table except the id. We will generate the id in the code using a module called UUID.
How to Set Up the Lambda Function
After creating the serverless.yml file, it is now time to create our lambda function which we defined inside the yml file. So let us get started on this.
We will again see different parts of the lambda function so you can understand it better.
Imports
const AWS = require("aws-sdk");
const { v4: uuidv4 } = require('uuid');
const rekognition = new AWS.Rekognition();
const dynamoDb = newAWS.DynamoDB.DocumentClient();
We are importing two packages, aws-sdk and UUID, to call the APIs for DynamoDB and AWS Rekognition. We are also initializing instances of them.
Define the Parameters
const Bucket = event.Records[0].s3.bucket.name;
const Name = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
const params = {
Image: {
S3Object: {
Bucket,
Name
}
}
};
When our lambda gets called by an S3 event, it receives data about the object which was uploaded to the S3 bucket. We are just getting that object data like the name of the Bucket it was uploaded to and the name of the file as well.
After that we are passing this data into the parameter object we will be passing to the AWS Rekognition API call.
Call the AWS Rekognition API
const celebrityData = await rekognition.recognizeCelebrities(params).promise();
if (celebrityData.CelebrityFaces && celebrityData.CelebrityFaces.length) {
const {
Name,
Urls,
KnownGender,
Face
} = celebrityData.CelebrityFaces[0];
const closelyMatchedEmotion = Face.Emotions.reduce(
(prev, current) => (prev.Confidence > current.Confidence) ? prev : current
);
const params = {
TableName: process.env.DYNAMO_TABLE_NAME,
Item: {
id: uuidv4(),
Name,
readMore: Urls,
KnownGender,
closelyMatchedEmotion
},
ConditionExpression: "attribute_not_exists(id)"
};
await dynamoDb.put(params).promise();
}
Finally, we are calling the AWS Rekognition API with the parameters we declared in the previous step. After we get the response from the API, we check to see if it was able to identify the celebrity or not.
If it found celebrity data, then we are fetching data like Name, Gender, Emotion in the image, and so on from the identified celebrity data.
Then we generate an id using the UUID package we imported earlier. The last thing we are doing is inserting this data into the DynamoDB table.
Querying Non-Key Attributes
To query this saved data with non-key attributes you will need to create an index if you do not wish to scan the whole table. Consider creating a DynamoDB Global Secondary Index for efficient querying by celebrity name or other attributes.
Complete Lambda Function Code
const AWS = require("aws-sdk");
const { v4: uuidv4 } = require('uuid');
const rekognition = new AWS.Rekognition();
const dynamoDb = new AWS.DynamoDB.DocumentClient();
module.exports.handler = async (event) => {
const Bucket = event.Records[0].s3.bucket.name;
const Name = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
const params = {
Image: {
S3Object: {
Bucket,
Name
}
}
};
const celebrityData = await rekognition.recognizeCelebrities(params).promise();
if (celebrityData.CelebrityFaces && celebrityData.CelebrityFaces.length) {
const { Name, Urls, KnownGender, Face } = celebrityData.CelebrityFaces[0];
const closelyMatchedEmotion = Face.Emotions.reduce(
(prev, current) => (prev.Confidence > current.Confidence) ? prev : current
);
const dbParams = {
TableName: process.env.DYNAMO_TABLE_NAME,
Item: {
id: uuidv4(),
Name,
readMore: Urls,
KnownGender,
closelyMatchedEmotion
},
ConditionExpression: "attribute_not_exists(id)"
};
await dynamoDb.put(dbParams).promise();
console.log(`Celebrity ${Name} saved to DynamoDB`);
} else {
console.log("No celebrity recognized in the image");
}
};
How to Deploy and Test
Create the S3 Bucket
Create a public S3 bucket in your AWS account and update the BUCKET_NAME environment variable in your serverless.yml file.
Install Dependencies
Run npm install aws-sdk uuid serverless to install all required packages.
Deploy the Application
Run serverless deploy to deploy your Lambda function, DynamoDB table, and all IAM permissions to AWS.
Upload a Celebrity Image
Go to your created S3 bucket and upload any celebrity image. Wait for a couple of seconds, then check the DynamoDB table to see the results saved there.
Enhancing the Application
You can enhance this application in many ways. For example you can add APIs like GET to get the data and see the data which got added to the DynamoDB table. You can also use MongoDB in place of DynamoDB.
Need Help Building AI-Powered Serverless Applications?
Braincuber's cloud experts can help you architect, build, and deploy serverless AI applications using AWS Rekognition, Lambda, and more. 500+ successful cloud projects delivered.
Frequently Asked Questions
What is AWS Rekognition and how does celebrity recognition work?
AWS Rekognition is a deep learning-based image and video analysis service. The RecognizeCelebrities API identifies celebrities in images and returns their names, URLs for more information, known gender, and facial attributes including detected emotions with confidence scores.
How does the S3 trigger invoke the Lambda function?
When you configure an S3 event notification for s3:ObjectCreated:*, AWS automatically invokes the Lambda function whenever a new object is uploaded to the bucket. The event payload contains the bucket name and object key.
What IAM permissions are needed for this application?
The Lambda function needs dynamodb:PutItem to write to DynamoDB, rekognition:RecognizeCelebrities to call the Rekognition API, and s3:Get*/s3:List* to retrieve the uploaded image from S3.
How do I query celebrity data by name instead of scanning the whole table?
Create a DynamoDB Global Secondary Index (GSI) with the Name attribute as the partition key. This allows efficient querying by celebrity name without scanning the entire table.
What data does AWS Rekognition return for identified celebrities?
For each identified celebrity, Rekognition returns the celebrity name, URLs for more information, known gender information, face bounding box, and a list of detected emotions with confidence scores (e.g., HAPPY, SAD, ANGRY).
