Hands-On Lab: Exploring Specialized AWS AI Services
Specialized AI Services
Hands-On Lab: Exploring Specialized AWS AI Services
Welcome to this guided hands-On lab! In this 30-minute session, you will learn how to interact with AWS's Specialized AI Services. These pre-trained models allow developers to seamlessly integrate powerful artificial intelligence capabilities into their applications without needing deep machine learning expertise.
We will focus on two core services from the AWS AI stack:
- Amazon Comprehend for Natural Language Processing (NLP) and sentiment analysis.
- Amazon Rekognition for Computer Vision and object detection.
Prerequisites
Before you begin, ensure you have the following requirements met:
- Cloud Account: An active AWS Account.
- IAM Permissions: An IAM User or Role with the following policies attached:
ComprehendFullAccessAmazonRekognitionFullAccessAmazonS3FullAccess
- Tools: AWS CLI installed and configured locally (
aws configure) with your access keys. - Sample Data: A local image file named
sample.jpg(e.g., a picture of a car, a city, or an animal) saved in your current working directory.
[!NOTE] Estimated Time: 30 minutes Difficulty: Guided
Learning Objectives
By completing this lab, you will be able to:
- Extract sentiment and meaning from unstructured text using Amazon Comprehend.
- Provision an Amazon S3 bucket to temporarily store image assets for computer vision tasks.
- Identify objects, scenes, and concepts within an image using Amazon Rekognition.
- Interpret the JSON bounding box coordinate system returned by computer vision APIs.
Architecture Overview
The following diagram illustrates the data flow for this lab. We will send text directly to Amazon Comprehend and route image data through Amazon S3 to be analyzed by Amazon Rekognition.
Step-by-Step Instructions
Step 1: Text Analysis with Amazon Comprehend
Amazon Comprehend is a fully managed NLP service that uncovers insights and relationships in text. We will use it to determine the emotional tone (sentiment) of a customer review.
aws comprehend detect-sentiment \
--text "I absolutely love the new AWS AI services! They make my job so much easier, though the setup was a bit confusing at first." \
--language-code en[!TIP] You can change the
--textpayload to any string you like. Try a purely negative or neutral sentence to see how the confidence scores adjust.
▶Console alternative
- Navigate to Amazon Comprehend in the AWS Management Console.
- In the left sidebar, click Real-time analysis.
- Scroll down to the Input text box and paste your sentence.
- Click the Analyze button.
- Scroll down to the Insights section and click the Sentiment tab to view the results.
📸 Screenshot: The Comprehend console showing the Sentiment tab with "POSITIVE" highlighted.
Step 2: Prepare S3 for Rekognition
Amazon Rekognition can analyze images stored directly in Amazon S3. We need to create a unique bucket and upload our sample.jpg file.
# Create a globally unique bucket (replace <YOUR_ACCOUNT_ID> and <YOUR_REGION>)
aws s3 mb s3://brainybee-lab-rekognition-<YOUR_ACCOUNT_ID> --region <YOUR_REGION>
# Upload your local image to the new bucket
aws s3 cp sample.jpg s3://brainybee-lab-rekognition-<YOUR_ACCOUNT_ID>/sample.jpg▶Console alternative
- Navigate to Amazon S3 in the AWS Console.
- Click Create bucket.
- Enter a globally unique name like
brainybee-lab-rekognition-12345and select your region. - Leave all other defaults and click Create bucket.
- Click on your newly created bucket, click Upload, add your
sample.jpgfile, and click Upload again.
📸 Screenshot: S3 Bucket object list showing
sample.jpgsuccessfully uploaded.
Step 3: Image Analysis with Amazon Rekognition
Now we will use Amazon Rekognition's Computer Vision capabilities to detect objects, scenes, and concepts (collectively called "labels") in the image we just uploaded.
aws rekognition detect-labels \
--image '{"S3Object":{"Bucket":"brainybee-lab-rekognition-<YOUR_ACCOUNT_ID>","Name":"sample.jpg"}}' \
--max-labels 5 \
--min-confidence 75[!TIP] The
--min-confidenceflag filters out predictions that the AI is not highly certain about. A value of is a standard baseline for production systems.
▶Console alternative
- Navigate to Amazon Rekognition in the AWS Console.
- In the left sidebar, click Label detection.
- Under the demo image, click Upload and select your
sample.jpgfrom your local machine. - Expand the Results pane on the right side to see the detected labels and their confidence scores.
📸 Screenshot: Rekognition console showing bounding boxes drawn over the uploaded image.
Step 4: Understanding Rekognition Bounding Boxes
When Rekognition detects a specific object (like a "Car" or a "Person"), it doesn't just tell you the object is there; it tells you exactly where it is by returning a BoundingBox object.
The coordinate system originates at the top-left corner of the image . The values are returned as ratios of the overall image width and height (from $0.0 to $1.0).
Checkpoints
Take a moment to verify your work. Run these checks before moving to the teardown phase:
- Checkpoint 1: Review your Comprehend output. Do you see a primary
"Sentiment"key (e.g.,"MIXED"or"POSITIVE"), accompanied by a"SentimentScore"object detailing the exact probabilistic breakdown? - Checkpoint 2: Verify S3 upload. Run
aws s3 ls s3://brainybee-lab-rekognition-<YOUR_ACCOUNT_ID>and confirmsample.jpgis listed. - Checkpoint 3: Review your Rekognition output. Do you see an array of
"Labels"? If the object is localized, do you see the"Instances"array containing"BoundingBox"coordinates?
Troubleshooting
If you run into issues, consult this table for common errors and their fixes:
| Error Message | Likely Cause | Solution |
|---|---|---|
AccessDeniedException | IAM User lacks permissions. | Ensure ComprehendFullAccess and AmazonRekognitionFullAccess are attached to your IAM user. |
InvalidS3ObjectException | Rekognition cannot find the image. | Check your bucket name and file name for typos. Ensure the file was actually uploaded. |
BucketAlreadyExists | S3 bucket name is not unique. | S3 bucket names must be globally unique. Add a random string or your AWS Account ID to the end. |
UnrecognizedClientException | Invalid AWS CLI credentials. | Run aws configure again and ensure your Access Key ID and Secret Access Key are correct. |
Clean-Up / Teardown
[!WARNING] Cost Warning: Leaving objects in Amazon S3 will incur ongoing storage charges. Amazon Rekognition and Comprehend charge per API call, so they will not accrue passive costs, but cleaning up storage is essential.
Run the following commands to delete the resources provisioned in this lab:
# 1. Delete the image file from S3
aws s3 rm s3://brainybee-lab-rekognition-<YOUR_ACCOUNT_ID>/sample.jpg
# 2. Delete the empty S3 bucket
aws s3 rb s3://brainybee-lab-rekognition-<YOUR_ACCOUNT_ID>Verify that the teardown was successful by running aws s3 ls and ensuring your lab bucket is no longer in the list.
Concept Review
In this lab, you experienced the primary advantage of AWS Specialized AI Services: you were able to execute complex machine learning tasks (NLP and Computer Vision) instantly via API calls, without needing to collect data, train a model, or manage underlying infrastructure (like you would with Amazon SageMaker).
| Feature | Specialized AI Services (e.g., Comprehend, Rekognition) | Custom ML (e.g., Amazon SageMaker) |
|---|---|---|
| Target Persona | Software Developers, Application Engineers | Data Scientists, ML Engineers |
| Ease of Use | High (Pre-trained, accessible via simple APIs) | Moderate to Advanced |
| Time to Market | Fast (Minutes to hours) | Slower (Weeks to months) |
| Customization | Limited (Though fine-tuning is sometimes available) | Infinite (Complete control over algorithms) |