Skip to content

fh17488/ImageWorkFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Objective

Build a state machine using AWS Step Functions that is triggered when an image is uploaded to an S3 bucket. In response the state machine should invoke two Lambda functions in parallel. These functions should be written in C#. The first Lambda function should identify objects in the image using the AWS Rekognition service and create a record in a DynamoDB table with the name and confidence of each identified object. The second Lambda function should generate a thumbnail and upload it to another S3 bucket. This application should be packaged and deployed using AWS SAM.

Components

  1. State Machine
  2. Lambda function for image recognition
  3. Lambda function for generating thumbnails
  4. S3 bucket for images
  5. S3 bucket for thumbnails
  6. DynamoDB table
  7. CloudWatch rule
  8. CloudTrail for CloudWatch rule
  9. S3 bucket for CloudTrail

State Machine

The type of state machine is express. It calls the Lambda functions in parallel and exits. Figure 1 below illustrates this state machine. The code for the State Machine can be found in the SAM template.

Image description

Lambda function for image recognition

This function is written in C#. It is based on a function available in the AWS repository. The function expects images with .png, .jpg or .jpeg extension. It will detect objects in the images using the AWS Rekognition service and will capture labels that AWS Rekognition identifies with a confidence of at least 90%. This value for minimum confidence can be overridden using the environment variable 'MinConfidence'. The labels and corresponding confidence of those labels are written to a DynamoDB table. The default name of this DynamoDB table is 'test_tbl' and this name can be overridden using the environment variable 'DynamoDBTableName'. Note that an external library has been included to parse the event object generated by the CloudWatch rule. The name of this library is Json.Net library, version 1.0.18, having a footprint of less than 65KB on disk.

The IAM permissions associated with this function should include the ability to invoke the GetObject API from the S3 bucket for images, PutItem API on the DynamoDB table and the permissions that are part of the managed policy 'AWSLambdaBasicExecutionRole'.

Lambda function for generating thumbnails

This function is written in C#. It is based on a function available in the AWS repository. The function expects images with .png, .jpg or .jpeg extension. It will create a thumbnail of size 100x100 pixels in the S3 bucket for thumbnails. The default name of this bucket is 'thumbnailtarget3005' and this can be overridden using the environment variable 'TargetBucketName'. Two external libraries have been included: the first to generate thumbnails and the second to parse the event object generated by the CloudWatch rule. The first library is GrapeCity.Documents.Imaging version 3.0.0.415 and the second library is Json.Net version 1.0.18.

The IAM permissions associated with this function should include the ability to invoke the GetObject API from the S3 bucket for images, the PutObject API to the S3 bucket for thumbnails and the permissions that are part of the managed policy 'AWSLambdaBasicExecutionRole'.

CloudWatch Rule

A rule will be configured to trigger the state machine when an object is uploaded to the S3 bucket for images. However, for this the PutObject API must be logged by CloudTrail. To configure this rule follow the instructions at the URL: https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-cloudwatch-events-s3.html.

The JSON object passed to the State Machine by the rule is given in the file 'event_obfuscated.json'. Some strings have been replaced by the token 'XXYZ' for security.

Note that this rule will have to be installed external to the SAM application.

Deployment

Download the ImageWorkFlow folder. Install AWS SAM CLI. Execute 'sam build' and then 'sam deploy'. This will result in a CloudFormation stack that will create all components except for the CloudWatch Rule, the CloudTrail S3 bucket and the CloudTrail trail needed for the CloudWatch Rule.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages