Skip to Content

AWS Serverless – How to Use AWS Rekognition to Identify Celebrities in Images

Posted on October 27, 2022 by

Categories: AWS


This tutorial will teach you how to create a celebrity picture recognition application using AWS Serverless. For AI-based identification, we’ll utilize AWS Rekognition.

We’ll add a Lambda function that will parse the data from the picture and store it in the DynamoDB database whenever a file is uploaded to the S3 bucket by attaching an event to the bucket.

Just be sure to read this article on AWS DynamoDB Pricing before using DynamoDB, so you only pay what you want to.

Tech Spec

Our project logic will be coded using Lambda functions, and AWS Rekognition will be used to identify the celebrity from their photograph using AI.

If the data we receive from the AWS Rekognition API is accurate, we will put it in a DynamoDB table.

The serverless.yml file will be used to build all of these resources except the S3 bucket.

project setup

We will put up everything we require for this project piece by piece. We’ll start by going over the serverless.yml file. Visit this site to find out more information about this file. Let’s begin with the first action.

By the end of this lesson, the folder structure for our project should be like this.

Setup instructions for the serverless.yml file

To make the serverless.yml file simpler to read, we will divide it into various sections.

How to configure the project service and establish permissions: meta-data-serverless

We are setting several environment variables and AWS IAM permissions that will be granted to our lambda functions in this code block. As a result, for our purposes, we must add something to the DynamoDB table, utilize the AWS Rekognition API to identify objects in the picture, and download the file from S3 (all of which are done in the code above).

A new public S3 bucket must be made, and its name must be entered here in place of “new-bucket-caps2” as the BUCKET NAME attribute. Visit the official AWS documentation to learn more about IAM roles.

How to include a lambda function:

We are defining a single lambda function in the functions block, and it will be called whenever any file is uploaded to the S3 bucket.

As you can see, we are associating this lambda function with the event that will cause it to be called. The s3:ObjectCreated event occurs whenever a file is uploaded to an S3 bucket.

We also state that this bucket exists by setting the existing option to true. Therefore, be careful to make this bucket before deploying the project.

We also use the environment variable we set up for the bucket name in the section before.