In this challenge we're going to explore AWS Step Functions while building an image analyzer that can identify and cut out faces (and also hot dogs) from images that are uploaded to S3.
- AWS Tools
- Sign-up for an AWS account
- Install AWS CLI
- .NET Core
- Install .NET Core 1.0 (NOTE: You MUST install 1.0. Do NOT install 1.1 or later!)
- Install Visual Studio Code
- Install C# Extension for VS Code
- AWS C# Lambda Tools
- Install the templates to the
dotnet
tool for AWS Lambda:dotnet new -i Amazon.Lambda.Templates::*
- Install the templates to the
Create an IAM Role in your aws account: lambdasharp-stepfunctions
and give the role the following Permissions:
AmazonS3FullAccess
AmazonRekognitionFullAccess
AmazonSNSFullAccess
AWSStepFunctionsFullAccess
For simplicity we will use this role for all our lambda functions, but feel free to implement more granular permissions if this approach is against your philosophy.
Please visit all files called aws-lambda-tools-defaults.json
and update all the relevant information to your AWS environment.
This function analyzes the provided image and performs face detection using AWS Rekognition.
In this repository, find the DetectFacesFunction/src/DetectFacesFunction
directory.
Run dotnet restore
and dotnet build
and finally dotnet lambda deploy-function
. This will deploy the function to your AWS account.
ACCEPTANCE TEST: Upload an image that contains human faces to S3, and run the lambda function with the sample input. Don't forget to replace the strings IMAGE_BUCKET
and IMAGE_KEY
with the appropriate values. The function should return URL's to the various faces that it detected in the input image.
Create a simple state machine using AWS Step Functions that will run our DetectFacesFunction.
Start -> DetectFaces -> End
ACCEPTANCE TEST: Run the state machine with the same input your used for your lambda function. Ensure your lambda function is run successfully.
So that we can focus on the fun stuff, we have provided you with a lambda function to serve as the glue in the folder TriggerStateMachineFunction/src/TriggerStateMachineFunction
Set up the lambda function to trigger when a file is uploaded to an S3 bucket. It is recommended that you create a folder called upload
and use that as your directory where you will upload your images to. Only trigger the step function on that directory prefix.
ACCEPTANCE TEST: When a file is uploaded to S3 the state machine is automatically run.
Write a lambda function that will analyze an image located on S3, and return true if the image contains a hot dog, false otherwise.
ACCEPTANCE TEST: The lambda function should accept the following sample input. I recommend you use DetectFacesFunction
as a starting point. The function should return true
if a hotdot is present in the image, and false
if it is not.
OPTIONAL MATERIAL: HotDogOrNot
The new state machine should look something like:
Start -> DetectFaces -> End
\ /
\ -> HotDogDetector -> /
** ACCEPTANCE TEST:** Detect faces and HotDogDetector run in parallel.
Introduce a random error somewhere in the DetectFacesFunction
code such as:
if(rand.Next(0, 3) == 2)) {
throw new MyRandomException()
}
ACCEPTANCE TEST: Ensure your state machine knows that this is not a permanent error and retries the operation. It should however still fail if other (more permanent) exceptions are thrown.
Write a final state that will merge the results from DetectFaces
and HotDogDetector
and notify you when a hot dog image is uploaded and how many faces were in the image.