Face recognition and comparison using AWS Rekognition API
- Face Detection: Detect faces in images with detailed analysis
- Face Comparison: Compare two faces and get similarity scores
- AWS Integration: Powered by AWS Rekognition API
- Real-time Analysis: Fast face recognition results
- HTTPS Support: Secure communication with SSL/TLS
- Image Upload: Direct image upload and analysis
- Node.js 14+ installed
- AWS Account with Rekognition enabled
- AWS credentials (Access Key ID and Secret Access Key)
# Clone the repository
git clone https://github.com/turanalmammadov/turanio-aws-rekognition.git
# Navigate to project directory
cd turanio-aws-rekognition
# Install dependencies
npm install- AWS Credentials Setup
Create assets/aws-config.json with your AWS credentials:
{
"accessKeyId": "YOUR_AWS_ACCESS_KEY_ID",
"secretAccessKey": "YOUR_AWS_SECRET_ACCESS_KEY",
"region": "us-east-2"
}- SSL Certificates (Optional)
For HTTPS support, place your SSL certificates in assets/:
assets/key.pem- Private keyassets/certificate.pem- SSL certificate
For development, you can generate self-signed certificates:
openssl req -x509 -newkey rsa:4096 -keyout assets/key.pem -out assets/certificate.pem -days 365 -nodes# Start the server
npm start
# Server will run on:
# HTTP: http://localhost:80
# HTTPS: https://localhost:5555Analyze a single face in an image.
Request:
{
"image": "data:image/png;base64,iVBORw0KGgoAAAANS..."
}Response:
{
"FaceDetails": [{
"BoundingBox": { ... },
"Confidence": 99.9,
"Emotions": [...],
"AgeRange": { ... },
"Gender": { ... }
}]
}Compare two faces and get similarity score.
Request:
{
"leftImage": "data:image/png;base64,...",
"rightImage": "data:image/png;base64,..."
}Response:
{
"FaceMatches": [{
"Similarity": 95.5,
"Face": { ... }
}],
"UnmatchedFaces": []
}Save uploaded images to server (for testing).
Request:
{
"leftImage": "data:image/png;base64,...",
"rightImage": "data:image/png;base64,..."
}βββββββββββββββ HTTPS ββββββββββββββββ AWS SDK βββββββββββββββββββ
β Client β βββββββββββββββ> β Express API β ββββββββββββββββ> β AWS Rekognition β
β (Browser) β β (Node.js) β β API β
βββββββββββββββ <βββββββββββββββ ββββββββββββββββ <ββββββββββββββββ βββββββββββββββββββ
JSON Response Process Result
- Backend: Node.js, Express.js
- Cloud: AWS Rekognition
- Security: HTTPS with SSL/TLS
- Image Processing: Base64 encoding/decoding
- CORS: Cross-origin resource sharing enabled
β οΈ Never commit AWS credentials to version control- β Use environment variables or AWS IAM roles in production
- β Implement rate limiting for production use
- β Add authentication/authorization middleware
- β Validate and sanitize all inputs
- β Use HTTPS in production
turanio-aws-rekognition/
βββ assets/
β βββ aws-config.json # AWS credentials (gitignored)
β βββ key.pem # SSL private key
β βββ certificate.pem # SSL certificate
βββ index.html # Frontend interface
βββ server.js # Express server + AWS integration
βββ package.json # Dependencies
βββ README.md # This file
You can use environment variables instead of config file:
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_REGION="us-east-2"
export PORT=3000# Start the server
npm start
# Open browser
open http://localhost:80
# Or test API directly
curl -X POST http://localhost:80/doFaceAnalysis \
-H "Content-Type: application/json" \
-d '{"image":"data:image/png;base64,..."}'-
DetectFaces: Detect faces and analyze attributes
- Age range estimation
- Gender detection
- Emotion analysis
- Face landmarks
- Quality assessment
-
CompareFaces: Compare facial features between images
- Similarity scoring (0-100%)
- Bounding box coordinates
- Confidence levels
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Face detection: ~1-2 seconds per image
- Face comparison: ~1-2 seconds per pair
- Depends on image size and AWS region latency
Error: "Missing credentials"
- Ensure
assets/aws-config.jsonexists and has valid credentials - Or set AWS environment variables
Error: "AccessDenied"
- Check AWS IAM permissions for Rekognition
- Required permissions:
rekognition:DetectFaces,rekognition:CompareFaces
Error: "Region not configured"
- Verify region in aws-config.json
- Ensure region supports Rekognition
HTTPS not working
- Generate SSL certificates (see Configuration section)
- Check if port 5555 is available
Turan Almammadov
- GitHub: @turanalmammadov
- Website: turanalmammadov.com
β If you find this project helpful, please give it a star!
