AWS Discovery Day - Image Recognition Handout
AWS Discovery Day - Image Recognition Handout
DISCLAIMER 3
Pre-requisites 5
Keywords 5
Resources Used 7
Frameworks/Libraries Used 7
Steps Overview 8
Screenshots 14
Useful Resources 15
3
DISCLAIMER
You might be billed for using the services on AWS for creating, using, distributing, or
evaluating this demo on your cloud provider accounts. To avoid charges while on the
AWS Free Tier, you must keep your usage below the AWS Free Tier limits.
You will be charged for any usage that exceeds the limits. To help you stay within the
limits, you can track your AWS Free Tier usage and set a billing alarm to notify you if
you start incurring charges. For tips about avoiding unexpected charges, see Avoiding
unexpected charges.
Ethnus or Codemithra will not be responsible for any cost incurred by you in any case.
We encourage students to consciously manage their resources and monitor their
costs. Ultimately you are responsible for managing your resources and therefore your
costs.
4
The image analysis recognizes and lists the labels of an image - attribute (Ex. Scenery, Dance,
Electronics, etc) and some facial attributes (if any) of the uploaded image.
5
Pre-requisites
To deploy the sample application you will require an AWS account. If you don’t already have an
AWS account, create one at https://aws.amazon.com by following the on-screen instructions.
Your access to the AWS account must have IAM permissions to launch the services that are
used in this demo. To use the sample application you will require a modern browser.
Keywords
Javascript, Express, Node.js, Amazon Web Services, Machine Learning, AWS SDK, AWS
Rekognition, Face Detection, Image Detection, AWS IAM
● Amazon Rekognition - Amazon Rekognition makes it easy to add image and video
analysis to your applications using proven, highly scalable, deep learning technology that
requires no machine learning expertise to use. With Amazon Rekognition, you can
identify objects, people, text, scenes, and activities in images and videos, as well as
detect any inappropriate content. Amazon Rekognition also provides highly accurate
facial analysis and facial search capabilities that you can use to detect, analyze, and
6
compare faces for a wide variety of user verification, people counting, and public
safety use cases.
● Amazon VPC - Amazon Virtual Private Cloud (Amazon VPC) is a service that lets you
launch AWS resources in a logically isolated virtual network that you define. You have
complete control over your virtual networking environment, including selection of your
own IP address range, creation of subnets, and configuration of route tables and network
gateways. You can use both IPv4 and IPv6 for most resources in your virtual private
cloud, helping to ensure secure and easy access to resources and applications.
● AWS Identity and Access Management (IAM) - AWS Identity and Access Management
(IAM) enables you to manage access to AWS services and resources securely. Using
IAM, you can create and manage AWS users and groups, and use permissions to allow
and deny their access to AWS resources. IAM is a feature of your AWS account offered
at no additional charge. You will be charged only for use of other AWS services.
7
Resources Used
● index.html: Markup for the static application
https://awsmc-dd.s3.ap-south-1.amazonaws.com/index.html
https://awsmc-dd.s3.ap-south-1.amazonaws.com/index.js
● server.js: Backend logic which invokes the Amazon Rekognition service on the user’s
behalf
https://awsmc-dd.s3.ap-south-1.amazonaws.com/server.js
https://awsmc-dd.s3.ap-south-1.amazonaws.com/package.json
Frameworks/Libraries Used
● Bootstrap v5
Bootstrap is a free and open-source framework for building the front end of the
application.
aws-sdk allows our application to access the AWS services on our behalf.
● Express
A node.js framework to serve our application and to provide API endpoints for the
frontend to invoke the functions to detect the labels and the facial expressions.
Steps Overview
● Go to https://aws.amazon.com/console/
● Create an EC2 Instance (server) on AWS
● Configure the OS, Instance Type, Storage, Security, and other settings for your EC2
Instance.
● Assign permissions (through the IAM role) to your EC2 instance to access the Amazon
Rekognition service.
● Launch the instance.
● Connect to the instance.
● In the terminal, type all the necessary commands, and once processed, your application
will be ready to use.
● Copy the public IP address of your EC2 Instance and paste it into the new tab in the
format <public ip>:3000 Example: http://13.107.178.22:3000
● You will be able to see the application running.
● Try uploading different images and inspect the response.
9
1. Go to https://aws.amazon.com/console/
2. After logging in, Navigate to the Console and select “EC2” from the services dropdown.
3. Click on “Launch Instance”
4. Select Amazon Linux 2 AMI (HVM), SSD Volume Type as the AMI
5. Select t2.micro type of instance and click on “Next: Configure Instance Details”
6. On this page (configure instance details or Step 3), we create an IAM role that gives
permissions to the EC2 to access the AWS Rekognition service on your behalf. Click on
“Create a new IAM role”
7. A new tab would be opened. Navigate to the new tab and click on on “Create Role”
8. Under “Choose a use case”, click on EC2 which would be under “Common use cases”
9. Now, we should attach the relevant permissions to our role. Search for
AmazonRekognitionFullAccess and tick the box so that it will be attached to our role.
10. Click next and here you can optionally add tags.
11. Click next and assign a name to the role. I am going to assign the name as
“aws-rekog-1”. Give a description and click “Create Role”.
12. Navigate to the previous tab, and click on the refresh button near “Create new IAM role”
13. Select the role that you just created. In my case it is aws-rekog-1. Now the IAM role
field should look like this.
14. Click on “Next: Add Storage” and after that “Next: Add Tags” and then “Next: Configure
Security Groups”. We will leave Storage and Tags as defaults.
15. In the security groups, Click on add a new rule and let the type of the new rule be
“Custom TCP Rule”. Fill in the rule and finally, the rules should look as follows.
10
16. The new rule is going to allow us to access the EC2 instance from anywhere. We would
be using the port number 3000 to host our application, but you can use any port number
greater than 1024.
17. Click “Review and Launch”. Review your configuration and click on Launch.
18. A pop-up window will appear. Fill the form as below:
19. You can give any name to your key pair. Download the key pair and keep it safe. After
that click on Launch Instances.
NOTE: You can also proceed without creating a key pair for this demo.
11
1. After the EC2 instance is created, connect to the EC2 instance by clicking on the
“Connect” button. This will open an SSH connection to the EC2 instance.
2. A terminal should appear like shown below
mkdir app
cd app
cd public
wget https://awsmc-dd.s3.ap-south-1.amazonaws.com/index.html
wget https://awsmc-dd.s3.ap-south-1.amazonaws.com/index.js
cd ..
12
cd server
wget https://awsmc-dd.s3.ap-south-1.amazonaws.com/package.json
wget https://awsmc-dd.s3.ap-south-1.amazonaws.com/server.js
npm install
3. In point 4, steps a-c create the directories. Steps d-f involve navigating to the folder
“public” and downloading index.html and index.js. Steps g-h involve navigating to the
folder server and downloading package.json and server.js. Package.json contains the
dependencies required by server.js. On doing npm install, those dependencies will be
installed
4. Execute the following command in the terminal
node server.js
5. The above command will start the server and the terminal should look like below
13
Step 4: Finish
1. You can find out the Public IP address of your EC2 Instance on the bottom left of the
terminal window. OR you can find the Public IP address of the EC2 instance in the EC2
Management Console. On selecting the newly created instance, the public IP address
will be shown in the properties of the selected EC2 instance.
2. Navigate to the browser and type the following:-
http://<IP_ADDDRESS>:3000
NOTE: The <IP_ADDDRESS> will be the IP address that you found in the previous step.
Example: http://13.107.178.22:3000
3. You would be able to see the webpage now. Congratulations! You have a working Image
recognizer and the power of deep learning at your disposal.
14
Screenshots
15
Useful Resources
● How do I create and activate a new AWS account?
● What is the AWS Free Tier, and how do I use it?
● How do I make sure I don't incur charges when I'm using the AWS Free Tier?
● I unintentionally incurred charges while using the AWS Free Tier. How do I make sure
that I'm not billed again?
● Avoiding unexpected charges while using AWS
● What should I do if I didn't receive a call from AWS to verify my new account?