Rekognition via SDK Best Practices
This is the checklist to run before and after taking a Rekognition workload to production from the SDK.
Busca en todas las páginas de la documentación
This is the checklist to run before and after taking a Rekognition workload to production from the SDK.
Each item is a rule stated positively, with a one-line rationale. Work top to bottom - the groups run from tuning the model's output, through responsible use, request patterns, Custom Labels cost, and finally reliability and security. Most rules apply whether you call Rekognition from boto3 or the AWS SDK v3.
MinConfidence is not the same as a certified negative.Tune per-operation rather than reusing one number everywhere.
# --- Python (boto3) ---
import boto3
rekognition = boto3.client("rekognition")
# Higher bar for a high-stakes verification flow; lower bar for casual tagging.
verify = rekognition.compare_faces(
SourceImage={"S3Object": {"Bucket": "my-bucket", "Name": "reference.jpg"}},
TargetImage={"S3Object": {"Bucket": "my-bucket", "Name": "submitted.jpg"}},
SimilarityThreshold=90,
)
tag = rekognition.detect_labels(
Image={"S3Object": {"Bucket": "my-bucket", "Name": "catalog/item.jpg"}},
MinConfidence=70,
)// --- TypeScript (AWS SDK v3) ---
import { RekognitionClient, CompareFacesCommand, DetectLabelsCommand } from "@aws-sdk/client-rekognition";
const rekognition = new RekognitionClient({});
// Higher bar for a high-stakes verification flow; lower bar for casual tagging.
const verify = await rekognition.send(new CompareFacesCommand({
SourceImage: { S3Object: { Bucket: "my-bucket", Name: "reference.jpg" } },
TargetImage: { S3Object: { Bucket: "my-bucket", Name: "submitted.jpg" } },
SimilarityThreshold: 90,
}));
const tag = await rekognition.send(new DetectLabelsCommand({
Image: { S3Object: { Bucket: "my-bucket", Name: "catalog/item.jpg" } },
MinConfidence: 70,
}));Image.Bytes caps at 5 MB; video operations only accept S3Object, never raw bytes.NotificationChannel avoids wasted Get* calls and reduces latency versus a fixed poll interval.RUNNING, independent of call volume.StartProjectVersion/StopProjectVersion to a batch job's lifecycle or a scaling policy rather than leaving a version on by default.Automate the start/stop discipline instead of relying on manual cleanup.
# --- Python (boto3) ---
import boto3
rekognition = boto3.client("rekognition")
version_arn = "arn:aws:rekognition:us-east-1:123456789012:project/parts-inspector/version/v1/1700000000000"
# Start before a batch job, stop immediately after - never leave it running idle.
rekognition.start_project_version(ProjectVersionArn=version_arn, MinInferenceUnits=1)
try:
pass # ... run DetectCustomLabels calls here ...
finally:
rekognition.stop_project_version(ProjectVersionArn=version_arn)// --- TypeScript (AWS SDK v3) ---
import { RekognitionClient, StartProjectVersionCommand, StopProjectVersionCommand } from "@aws-sdk/client-rekognition";
const rekognition = new RekognitionClient({});
const versionArn = "arn:aws:rekognition:us-east-1:123456789012:project/parts-inspector/version/v1/1700000000000";
// Start before a batch job, stop immediately after - never leave it running idle.
await rekognition.send(new StartProjectVersionCommand({ ProjectVersionArn: versionArn, MinInferenceUnits: 1 }));
try {
// ... run DetectCustomLabels calls here ...
} finally {
await rekognition.send(new StopProjectVersionCommand({ ProjectVersionArn: versionArn }));
}RUNNING version is a silent, ongoing cost until someone notices.Leaving a Custom Labels project version RUNNING when it isn't actively serving traffic. Inference-unit-hours bill continuously regardless of request volume, so an idle version left on overnight or over a weekend adds up fast.
Only as a starting point. Test both against a labeled sample of your own images and tune per use case - a high-stakes verification flow and a casual tagging feature warrant very different thresholds.
For anything consequential to a person, no. Use confidence bands with a human review step for borderline cases, and never treat estimated face attributes as verified facts.
Use NotificationChannel so Rekognition pushes completion to SNS instead of polling, and always page through Get* results with NextToken rather than assuming one call returns everything.
Yes. Confidence tuning, responsible use, Custom Labels start/stop discipline, and reliability patterns are the same regardless of which SDK you call Rekognition from - only the syntax differs.
No. Create one client and reuse it across calls so connection pooling and resolved credentials are shared, which lowers latency, especially in long-running services or warm Lambda invocations.
Add a scheduled check (a cron job or CloudWatch alarm) that lists project versions and alerts if any are RUNNING outside expected batch windows, since there is no automatic idle-shutoff.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+).
Revisado por Chris St. John·Última actualización: 24 jul 2026