Name: amazon-rekognition-policing-user-content
Owner: AWS Samples
Description: A Stepfunctions driven workflow to use Amazon Rekognition to scan incoming images through a set of business rules and police apply policing
Created: 2017-11-03 21:09:45.0
Updated: 2017-12-19 19:00:31.0
Pushed: 2017-12-07 19:29:42.0
Homepage: null
Size: 17726
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Stepfunctions driven workflow to use Amazon Rekognition to scan incoming images through a set of business rules and police apply policing, using AWS services like Amazon Rekognition, AWS Step Functions, Amazon DynamoDB and AWS Lambda.
Images can be captured by a camera (or a mobile device) and uploaded to S3. The image capture mechanism can be a website too. Once the image lands on the S3 bucket, the step functions flow can be triggered using a S3 event + Lambda (The S3 event triggering code is not included in this repository). Step functions then executes a series of checks with Amazon Rekognition and builds a json template of its findings, as it progresses through the workflow. The process is successful if all the steps succeed and unsuccessful if any of them fails. The results are logged into Amazon Elasticsearch service and you use Kibana to visualize the results.
This repository contains the sample code for Lambda functions and Step functions as well as a SAM template to deploy the resources in an AWS region of your choice.
The following checks are implemented as a part of this workflow:
This code depends on a bunch of libraries (not included in this distribution) which you will have to install yourself. You will be needing AWS CLI as well.
Download the contents of this repository on your local machine (say: project-directory)
The solution is implemented in python, so make sure you have a working python environment on your local machine.
Open a command prompt, navigate to the project directory. Navigate to the /code sub directory and install the following libraries:
install requests_aws4auth --target .
install elasticsearch --target .
Create a S3 bucket for deployment (note: use the same region throughout the following steps, I have used us-east-2, you can replace it with the region of your choice. Refer to the region table for service availability.)
s3 mb s3://rekdemo2017 --region us-west-2
Prepare the SAM template: Open the Rek_Demo.yaml with your favorite editor and change the change the BucketName property of 'RekS3Bucket' to your choosing (say: S3Bucket). This is the bucket which will house the input images and the blacklist images to the StepFunctions state machine.
Package the contents and prepare deployment package using the following command
cloudformation package --template-file Rek_Demo.yaml --output-template-file Rek_demo_output.yaml --s3-bucket rekdemo2017 --region us-west-2
Deploy the package
cloudformation deploy --template-file Rek_demo_output.yaml --stack-name RekDemoStack --capabilities CAPABILITY_IAM --region us-west-2
If you want to make changes to the Lambda functions, you can do so on your local machine and redeploy them using the steps 6 and 7 above. The package and deploy commands take care of zipping up the new Lambda files(along with the dependencies) and uploading them to AWS for execution.
Following are the outputs from the SAM template
The StepfunctionInput.json file contains sample invocations that you can use to trigger the worklow. The Step Functions state machine expects input to be passed in a particular format. You can change the values, but the structure is expected by the lambda functions that are triggered by the state function.
For a successful iteration, you can expect all the states successfully executed. Below is the sample input to the 'ProcessSuccess' state. You can expect this input to the lambda function associated with this state and apply your custom processing logic in this lambda function.
arams": {
"Bucket": "mayankdemo1-us-west-2",
"Key": "reInvent2017/RekognitionDemo/InputImages/person1.jpg"
verallResult": {
"Reason": "",
"Details": [
{
"Pass": true,
"ErrorMessages": [
"Gender of Face = Female"
],
"Stage": "DetectFaces"
},
{
"ErrorMessages": [],
"Stage": "RecognizeCelebrities",
"Pass": true
},
{
"Pass": true,
"ErrorMessages": [],
"Stage": "DetectModerationLabels"
},
{
"ErrorMessages": [],
"Stage": "CheckBlackList_Dups",
"Pass": true
},
{
"ErrorMessages": [
"Image added to collection."
],
"Pass": true,
"Stage": "ProcessImage"
}
],
"Pass": true
For a failed iteration, you can expect only some of the states successfully executed. Below is the sample input to the 'ProcessFailure' state, when a duplicate is detected. You can expect this input to the lambda function associated with this state and apply your custom processing logic in this lambda function.
arams": {
"Bucket": "mayankdemo1-us-west-2",
"Key": "reInvent2017/RekognitionDemo/InputImages/person1.jpg"
verallResult": {
"Reason": "BLACKLIST_DUPS_DETECTED",
"Details": [
{
"ErrorMessages": [
"Gender of Face = Female"
],
"Stage": "DetectFaces",
"Pass": true
},
{
"Pass": true,
"ErrorMessages": [],
"Stage": "RecognizeCelebrities"
},
{
"ErrorMessages": [],
"Stage": "DetectModerationLabels",
"Pass": true
},
{
"ErrorMessages": [
"Duplicate Image Detected."
],
"Pass": false,
"Stage": "CheckBlackList_Dups"
}
],
"Pass": false
This library is licensed under the Apache 2.0 License.