Amazon Rekognition makes it easy to extract meaningful metadata from visual content. This workshop includes multiple exercises during which attendees will use Rekognition to build practical use cases. Each module provides best practices for integrating Rekognition with other AWS services in real-world scenarios that help developers build image analysis quickly and confidently into their own applications.
2. Workshop Architecture
You can have many cameras taking
pictures in the store, these images
can be use for multiple purposes e.g.
facial recognition etc. You will:
1. Produce multiple images
2. Durably ingest and store the
images in S3 bucket
3. Perform real time meta-data
generation using Rekognition
4. Use Athena to perform ad-hoc
queries
5. QuickSight to build dashboards.
S3
Lambda Rekognition
Bucket
Athena QuickSight
3. Objectives for Today
Build an application using Amazon Rekognition and learn how we can
analyze image meta data using Amazon Athena
At the end of the workshop, you will:
1. Understand how to invoke Rekognition APIs
2. Understand how to create DB/table in Athena
3. Understand how to build dashboard in QuickSight by connecting
directly with Athena
7. Activity 1: Setting up IAM role and S3 buckets
We are going to:
A. Create an AWS IAM role for Lambda function execution
B. Create S3 bucket for input and output folders for the image
processing
We will use durable S3 service to store the captured images. S3 is an
ideal service to store large number of data set as it provides 11 9s
durability and automatic scalability. This solution will read input images
from S3 bucket and will put meta data in the output folders.
8. Activity 1-A: Create an AWS IAM Role
You can use AWS IAM to securely control individual and group access to
your AWS resources. You can create and manage user identities ("IAM
users") and grant permissions for those IAM users to access your
resources. To grant permissions, you create policy documents that you
attach to users, groups, or other entities.
In Activity 1-A, you will create an IAM role and attach policies to
allow Lambda function access to Rekogniton Service, S3 bucket
and CloudWatch logs. We will attaching this role when we
configure S3 event later on.
9. Activity 1-A: Create an AWS IAM Role
1. Go to the AWS IAM console, click “Users”
1. https://console.aws.amazon.com/iam/home?region=us-east-
1#/roles
2. Choose “Create Role” on the upper left hand side
10. Activity 1-A: Create an AWS IAM role
3. Select RoleType from
“AWS Service Role”
4. Click on AWS Lambda
“Select” button
11. Activity 1-A: Create an AWS IAM role
6. Choose “Attach policies”
and then select following
policies
“AmazonS3FullAccess”,
“AWSLambdaExecute” and
”AmazonRekognitionFullAc
cess”
7. Click on “Next Step”
12. Activity 1-A: Create an AWS IAM role
8. Choose name for the role
for “Role Name” field
9. Provide description for the
role in “Role Description” field
10. Click on “Create Role”
button
13. Activity 1-B: Create S3 Buckets
Click on Service management
console and select S3.
Click on “Create bucket”
button
14. Activity 1-B: Create S3 Buckets
1. Provide unique “Bucket Name” and
select region you want to create
bucket in
2. Click on “Next” button
Note: Please ensure that the bucket is created in same region where rest of the application will be.
Bucket name has to be globally unique and should be selected sensibly.
15. Activity 1-B: Create S3 Buckets
1. In next page leave the default setting
and click on ”Next” button
2. Next page is for setting permissions,
leave the default setting and click on
“Next” button
3. Review the setting and click on
“Create Bucket” button.
Note: Please ensure that the bucket is created in same region where rest of the application will be.
Bucket name has to be globally unique and should be selected sensibly.
16. Activity 1-B: Create S3 Buckets
1. On main page click on “Create folder”
button
2. Create following folders
1. csv
2. json
18. Activity 2: Setting up Lambda function to process
Images
We are going to:
A. Create a Lambda function using python 2.7
B. Configure S3 event to invoke Lambda function
19. Activity 2: Setting up Lambda function
1. Go to the AWS Management
Console
2. From the Services menu on the
AWS Management Console, select
Lambda service
3. Click on “Create a Lambda
function” button
Please make sure Lambda function is created in
same region as S3 bucket.
20. Activity 2: Setting up Lambda function
1. In the “Select Blueprint” screen, select
“s3-get-object-python” option
21. Activity 2: Setting up Lambda function
1. In “Configure trigger” screen fill up
following information:
1. Select the bucket name from
the drop down
2. In EventType dropdown select
“Object Created (All)”
3. In Suffix field specify “jpg”
4. Check “Enable Trigger” check
box
5. Click on “Next” button
22. Activity 2: Setting up Lambda function
1. In “Configure Function” screen fill
up following information:
1. In “Name” field provide name
for Lambda function
2. In “Runtime” dropdown select
Python 2.7
3. Copy lambda function from
downloaded file to “Lambda
function code” section
Ensure that Runtime is selected as Python 2.7
23. Activity 2: Setting up Lambda function
1. In “Lambda function handler and role”
section:
1. In “Role” dropdown select “Choose
an existing role”
2. In ”Existing Role” dropdown select the
role we created in step 1.
2. Click on “Next” button
3. Next page review the information and
click on “Create function” button
25. Activity 3: Setup Athena Service
1. Open the AWS Management
Console by clicking Open
Console.
2. From the Services menu on the
AWS Management Console, select
Athena Service
26. Activity 3: Setup Athena Service
Click on “Add Table” section
1. In Database drop down select “Create
New Database”
2. Provide Database name
3. Provide Table name
4. In “Location of Input of Data Set”
provide the S3 bucket we created as
part of step 2
s3://<region_name>/bucket_name e.g. s3://us-east-1/2017-ai-demo/csv
27. Activity 3: Setup Athena Service
To save time let’s paste the SQL
statement in the query editor
28. Activity 3: Setup Athena Service
CREATE EXTERNAL TABLE IF NOT EXISTS <db_name>.<table_name> (
`ImageLocation` string,
`Timestamp` string,
`Gender` string,
`Smiling` string,
`Beard` string,
`Mustache` string,
`Sharpness` string,
`Brightness` string,
`MouthOpen` string,
`EyesOpen` string,
You can download SQL file from following link:
https://s3.amazonaws.com/sfloftrekognitionmay09/Athena_TBL_Def.sql.txt
29. Activity 3: Setup Athena Service
`LowAgeRange` string,
`HighAgeRange` string,
`Eyeglasses` string,
`Sunglasses` string
)
ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
WITH SERDEPROPERTIES (
'serialization.format' = ',',
'field.delim' = ','
) LOCATION 's3://<bucket_name>/csv/'
Please don’t specify region detail in S3
bucket name
30. Activity 3: Setup Athena Service
To run the query select on
Eye icon next to table name
32. Activity 4: Testing
Let’s test this before we setup
QuickSight dashboard
1. Upload sample images we
downloaded earlier to S3 bucket.
2. Once files are placed Lambda
function will kick off and place files in
csv and json folder
3. Go to Athena service and run select
query and data should be
populated in the table
Sample CSV File:
Sample Athena table data:
33. Activity 4: Testing
Let’s run some queries with where clause
Select * from <database_name>.<table_name> where gender=’Female’
35. Activity 5: Setup Amazon QuickSight Dashboard
1. In QuickSight Service menu
Select Athena as data
source
2. Specify Athena DB name in
“Data Source name” field
3. Click on “Create data
source” button
36. Activity 5: Setup Amazon QuickSight Dashboard
1. Select the table name from the
list
2. Select how you want to query
the data either directly from
the source or load it up in
memory first. For this lab you
can choose either
37. Activity 5: Setup Amazon QuickSight Dashboard
From designer window you can choose type of graph you
want to build as well data you want to see. This example
shows graph between count of people who are smiling by
gender
39. Activity 6: Clean up
1. Make sure you delete the sample images from
the S3 bucket and then S3 bucket itself
2. Delete the Athena table and database
3. Delete the Lambda function
41. Summary
1. Fully managed and easy-to-use image recognition
service
2. Four primary capabilities
• Object and Scene Detection
• Facial Analysis
• Face Comparison
• Face Recognition
3. Integrated with AWS and AI Services
• Amazon S3
• Lex and Polly
4. Scalable and low cost