Shows you how to use the AWS SDK for Python (Boto3) to create a web application that lets you do the following:
- Upload photos to an Amazon Simple Storage Service (Amazon S3) bucket.
- Use Amazon Rekognition to analyze and label the photos.
- Use Amazon Simple Email Service (Amazon SES) to send email reports of image analysis.
This example contains two main components: a webpage written in JavaScript that is built with React, and a REST service written in Python that is built with Flask-RESTful.
You can use the React webpage to:
- Display a list of images that are stored in your S3 bucket.
- Upload images from your computer to your S3 bucket.
- Display images and labels that identify items that are detected in the image.
- Get a report of all images in your S3 bucket and send an email of the report.
The webpage calls the REST service. The service sends requests to AWS to perform the following actions:
- Get and filter the list of images in your S3 bucket.
- Upload photos to your S3 bucket.
- Use Amazon Rekognition to analyze individual photos and get a list of labels that identify items that are detected in the photo.
- Analyze all photos in your S3 bucket and use Amazon SES to email a report.
- Running this code might result in charges to your AWS account.
- Running the tests might result in charges to your AWS account.
- We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
- This code is not tested in every AWS Region. For more information, see AWS Regional Services.
The requirements for the webpage are listed in the accompanying package.json
file.
You will need recent versions of Node.js and npm to install the requirements.
- Node.js 16.14.2
- npm 8.5.0
Install the webpage requirements by running the following in the frontend
folder
at a command prompt:
npm install
This installs components like React, React-Bootstrap, and jQuery.
The requirements for the REST service are listed in the accompanying requirements.txt
file. You will need recent versions of Python and pip to the install the requirements.
- Python 3.8.8
- pip 21.1.2
Install the REST service components by running the following in the api
folder in
a virtual environment:
python -m pip install -r requirements.txt
This installs components like Boto3, Flask, and Flask-RESTful.
The example requires an S3 bucket to store photos. You can create an S3 bucket by using the AWS Management Console.
After you create your bucket, update the BUCKET_NAME
field in api\config.py
with
the name of your bucket.
The example sends an email report by using Amazon SES. When your account is in the sandbox, you must register both the sender and recipient email addresses. You can do this by using the console.
Tip: For this example, you can register the same email account as both the sender and the recipient.
Start the REST service by running the following at a command prompt in the api
folder:
python app.py
This starts the Flask web server in debug mode on http://localhost:5000.
Start the webpage in development mode by running the following at a command prompt
in the frontend
folder:
npm start
This compiles the project and browses to it at http://localhost:3000.
By default, the application shows that your bucket contains no images.
Select Browse, choose a JPG or PNG file, and select Upload to upload it to your S3 bucket.
Select the image in the list to display it along with labels detected by Amazon Rekognition. When a label includes bounding boxes, it is added to a list of clickable items. Select one to draw boxes over the image.
Select Analyze all photos in your bucket and send a report to use Amazon Rekognition to analyze all photos in your bucket and display a report.
Fill out the form with sender address, recipient address, and a message. Select Send report to email the report.
To avoid charges, use the console to delete all the resources that you created for this tutorial.
- Empty and delete your S3 bucket.
- Delete your email from Amazon SES.
Congratulations! You have built a web application that uploads and lists photos in an S3 bucket, uses Amazon Rekognition to analyze photos, and uses Amazon SES to send email to a registered user.
- Cross-service examples
- Amazon Rekognition Developer Guide
- Amazon S3 User Guide
- Amazon SES Developer Guide'
- Amazon Rekognition API Reference
- Amazon S3 API Reference
- Amazon SES API Reference
- Amazon Rekognition Boto3 API Reference
- Amazon S3 Boto3 API Reference
- Amazon SES Boto3 API Reference
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0