The Image Recognition and Processing Backend reference architecture demonstrates how to use AWS Step Functions to orchestrate a serverless processing workflow using AWS Lambda, Amazon S3, Amazon DynamoDB and Amazon Rekognition.
The Image Recognition and Processing Backend demonstrates how to use AWS Step Functions to orchestrate a serverless processing workflow using AWS Lambda, Amazon S3, Amazon DynamoDB and Amazon Rekognition. This workflow processes photos uploaded to Amazon S3 and extracts metadata from the image such as geolocation, size/format, time, etc. It then uses image recognition to tag objects in the photo. In parallel, it also produces a thumbnail of the photo.
This repository contains sample code for all the Lambda functions depicted in the diagram below as well as an AWS CloudFormation template for creating the functions and related resources. There is also a test web app that you can run to interact with the backend.
PhotoRepo
S3 bucket under the private/{userid}/uploads
prefixS3Trigger
Lambda function, which kicks off an execution of the ImageProcStateMachine
in AWS Step Functions, passing in the S3 bucket and object key as input parameters.ImageProcStateMachine
has the following sub-steps:NotSupportedImageType
error and end execution.ImageMetadata
DynamoDB tableImageMetadata
DynamoDB tableprivate/{userid}/resized
prefix in the PhotoRepo
S3 bucketFollow these instructions to deploy the application (both backend and frontend):
If you want to make changes to the code locally:
amplify pull --appId <your app id> --envName <your env name>
command displayed
amplify init --appId
, try refreshing the backend environment tab after waiting a few minutes (cloudformation could still be provisioning resources) - This command synchronizes what's deployed to your local Amplify environment
- Do you want to use an AWS profile: Yes
- default
- Choose your default editor: Visutal Studio Code
- Choose the type of app that you're building: javascript
- What javascript framework are you using: react
- Source Directory Path: src/react-frontend/src
- Distribution Directory Path: src/react-frontend/build
- Build Command: npm.cmd run-script build
- Start Command: npm.cmd run-script start
- Do you plan on modifying this backend? (Yes)
If at anytime you want to change these options. Look into amplify/.config/project-config.json
and make your changes there.
You can use the test web app to upload images and explore the image recognition and processing workflow.
Go to the URL of the Amplify app that was deployed
In the login page, click on “Create account”
Register an account by following the sign up instructions
After confirming the account, sign in
Click into an album you created
Upload a photo
You can follow the Step Functions execution link to review the details of the workflow execution
Below is the diagram of the state machine being executed every time a new image is uploaded
(you can explore this in the Step Functions Console):
When the processing finishes, the photo and extracted information is added to the display
To remove all resources created by this example, do the following:
This reference architecture sample is licensed under Apache 2.0.