Combining AWS Rekognition Image Tags with a Lambda Function
Amazon’s AWS Rekognition has separate services for returning Image Tags from their model and Image Tags from your custom trained model. There is nothing that I could find that combines the two in one list.
I created a Lambda Function and use the API Gateway as a trigger to call it. This allowed me to integrate with Sitecore’s Content Hub using 1 connection point.
The Solution
🔗 GitHub Repo: AWSRekognitionCombineTags
The script is heavily commented at the top of the script. It includes details on which Environment Variables you have to create to wire it up as well as the IAM Permissions required to run it.
Architecture
API Gateway → Lambda Function → AWS Rekognition Services → Combined Results
This setup provides a single endpoint that internally calls both:
- AWS Rekognition - for general image tagging
- Custom Rekognition Model - for domain-specific tagging
Important Caveats
1. Hosting Costs 💸
Even on the free tier it was costing me $4 an hour to host the model with the Image Tags. Thank you Amazon Support for removing that charge! This was all just an educational experiment on my personal account.
Lesson: Be very careful with model hosting costs on AWS!
2. Image Data Format 📸
You have to pass the image as a byte array. Neither service has an option to pass a URL… This increases the amount of memory required to pass the image along to the backend services. There are instructions inside of the script to increase the amount of memory based on your image size.
3. API Key Format 🔑
Regardless of what you name your API Key in the API Gateway it needs to be passed as x-api-key.
Development Experience
This was a very pleasurable experience and learning journey outside of my panic attack when I saw my AWS bill! 😅
I found training and deploying the model in Rekognition to be very intuitive. I spend most of my time in Microsoft’s Azure so I enjoyed the exposure to:
- AWS Rekognition - Image analysis service
- Lambda Functions - Serverless compute
- API Gateway - REST API management
Comparison with Azure
This solution is the AWS equivalent of my Azure Vision combine tags function. Both solve the same problem but with different cloud providers:
| Feature | AWS Solution | Azure Solution |
|---|---|---|
| Compute | Lambda Function | Azure Function |
| API Management | API Gateway | Function HTTP Trigger |
| Image Input | Byte Array | Image URL |
| Cost Model | Pay per invoke + model hosting | Pay per invoke |
Use Cases
Perfect for:
- Content Management Systems - Automated image tagging
- E-commerce Platforms - Product categorization
- Digital Asset Management - Enhanced searchability
- Sitecore Content Hub Integration - Single API endpoint
This was an educational experiment that taught me a lot about AWS services. The cost lesson was expensive but valuable! Check out my Azure equivalent solution for a cost-effective alternative.