Author: Vladimir Budilov

You can watch the video explanation of this architecture here

Serverless Photo Recognition

What is it?

A collection of 3 lambda functions that are invoked by Amazon S3, Amazon API Gateway, and directly (RESTful calls) to analyze uploaded images in S3 with Amazon Rekognition and save picture metadata to ElasticSearch

Before you start

  1. When you run the setup script your account will start incurring AWS infrastructure costs.
  2. This project was written a while back, before CloudFormation was available for all of the services in use, hence my use of the AWS CLI. If I were to write this today I would use CDK to create all of the resources (from IAM roles to ElasticSearch service). Check out this project for a reference.

The Architecture

Adding an image

Adding an image

Removing an image

Remove an image

Searching images

Search images

Tech Stack

Required Tools

AWS Services Involved In This Architecture

AWS Setup

Before we start, let’s make sure that your working environment is setup to run the script. Here's what you'll need:

  • An AWS Account with a default VPC
  • Java 8
  • The latest AWS CLI (Tested with aws-cli/1.11.29 Python/2.7.12)
  • Linux or Mac OS to run the setup script (the setup script won't work on Windows)

The following command will setup all of the needed resources, as well as print out the sample command that you can run to test your configuration:

# Clone it from github
git clone --depth 1
# Run the installation script
cd serverless-photo-recognition/setup

Running the installation script will modify the /src/main/kotlin/com/budilov/Properties.kt file with the newly-generated values. If you need to rerun the script, just revert the changes (otherwise the script will fail).

It will also create a deletion script under the tmp directory

At the end of the script, you'll see 3 commands (customized with your environment variables) that you can run to test out your configuration. Run the commands and see the functionality in action (copying and running the below commands will fail...use the ones that the script has generated):

-> Upload a picture
aws s3 cp new-york.jpg s3://rekognition-20170307160632/usercontent/us-east-1:c61126b8-7f7b-48e8-8534-4c3a21dfef4e/

-> Sample search command
You might need to pipe the output to 'native2ascii -encoding UTF-8 -reverse' if you
want to copy and paste the signed url in the browser since curl encodes url output
curl -X POST -H "Authorization: $(aws cognito-idp admin-initiate-auth  --user-pool-id us-east-1_AEzYFK4mc --client-id 734810igh3bfdj4n33tfm9o08s --cli-input-json file:///tmp/authflow.json --query AuthenticationResult.IdToken --output text)" -H "search-key: building" -H "Cache-Control: no-cache" ""

-> Remove the picture
aws s3 rm s3://rekognition-20170307160632/usercontent/us-east-1:c61126b8-7f7b-48e8-8534-4c3a21dfef4e/new-york.jpg

Serverless Photo Recognition

A collection of 3 lambda functions that are invoked by Amazon S3 or Amazon API Gateway to analyze uploaded images with Amazon Rekognition and save picture labels to ElasticSearch (written in Kotlin)

Serverless Photo Recognition Info

⭐ Stars 327
πŸ”— Homepage
πŸ”— Source Code
πŸ•’ Last Update a year ago
πŸ•’ Created 5 years ago
🐞 Open Issues 2
βž— Star-Issue Ratio 164
😎 Author awslabs