Hands-On Lab: Exploring AI Concepts with AWS Managed Services
AI Concepts and Terminology
Hands-On Lab: Exploring AI Concepts with AWS Managed Services
Welcome to this guided lab! In this session, we will bridge the gap between theoretical Artificial Intelligence (AI) concepts and practical implementation. You will work with unstructured data, perform real-time inferencing, and see the difference between Computer Vision (CV) and Natural Language Processing (NLP) using AWS managed services.
Prerequisites
Before you begin, ensure you have the following ready:
- AWS Account: An active AWS account with an IAM user or role that has
AdministratorAccess(or permissions for Amazon S3, Amazon Rekognition, and Amazon Comprehend). - AWS CLI: The AWS Command Line Interface installed and configured (
aws configure) with your credentials and a default region (e.g.,us-east-1). - Basic Terminal Knowledge: Familiarity with running commands in a bash/zsh or PowerShell terminal.
- Conceptual Understanding: Basic awareness of AI, ML, Computer Vision, and NLP as covered in the study guide.
Concept Review: The AI Hierarchy
Before we build our architecture, let's review the relationship between AI, Machine Learning (ML), and Deep Learning (DL). The services we will use today abstract away the deep learning layers, allowing you to focus on the AI application.
Learning Objectives
By the end of this lab, you will be able to:
- Differentiate Data Types: Handle unstructured data (images and raw text) in an AI pipeline.
- Execute Real-Time Inferencing: Send single-request data to pre-trained foundation models and receive immediate predictions.
- Apply Computer Vision (CV): Use Amazon Rekognition to extract Optical Character Recognition (OCR) data from an image.
- Apply Natural Language Processing (NLP): Use Amazon Comprehend to determine the sentiment of a text string.
Architecture Overview
The following flowchart visualizes the data flow for this lab. We will use the CLI to interact with unstructured data (an image), extract text using a CV model, and then analyze text using an NLP model.
Step-by-Step Instructions
Step 1: Create a Storage Bucket for Unstructured Data
AI models require data. In this step, we will create an Amazon S3 bucket to hold our unstructured data (images).
aws s3 mb s3://brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>[!TIP] S3 bucket names must be globally unique. Replace
<YOUR_ACCOUNT_ID>with your actual AWS account number or a random string of numbers to ensure the name is available.
▶Console alternative
- Navigate to the S3 Console.
- Click Create bucket.
- Enter
brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>as the Bucket name. - Leave all other settings as default and click Create bucket.
📸 Screenshot: S3 Create Bucket Form
Step 2: Download and Upload an Image
We need an image containing text to test our Computer Vision model. We will download a sample image and upload it to our new S3 bucket.
# Download a sample image containing text
curl -o sample-text.jpg https://raw.githubusercontent.com/aws-samples/amazon-rekognition-code-samples/master/images/text.jpg
# Upload it to your S3 bucket
aws s3 cp sample-text.jpg s3://brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>/▶Console alternative
- Download the image from this link to your computer.
- Navigate to your newly created S3 bucket in the console.
- Click Upload, select your downloaded
sample-text.jpg, and click Upload.
Checkpoints
Let's verify our unstructured data is safely stored in S3.
aws s3 ls s3://brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>/Expected Output: You should see sample-text.jpg listed with its timestamp and file size.
Step 3: Perform Real-Time Inferencing with Computer Vision (CV)
Now, we will use Amazon Rekognition, a managed Deep Learning service for Computer Vision. We will perform real-time inferencing to detect text (OCR) within our unstructured image.
aws rekognition detect-text \
--image '{"S3Object":{"Bucket":"brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>","Name":"sample-text.jpg"}}' \
--region us-east-1[!NOTE] Look at the JSON output. This represents a model prediction. The service returns
DetectedTextand aConfidencescore (a percentage indicating how certain the ML algorithm is about its prediction).
▶Console alternative
- Navigate to the Amazon Rekognition Console.
- In the left sidebar, choose Text in image.
- Expand the Upload dropdown and upload your local
sample-text.jpg. - View the extracted text results and confidence scores in the Results pane on the right.
📸 Screenshot: Rekognition Text Detection Results
Step 4: Perform Real-Time Inferencing with Natural Language Processing (NLP)
Next, let's explore Natural Language Processing (NLP). We will use Amazon Comprehend to analyze the sentiment of a sentence. This is an example of taking unstructured text and turning it into structured, labeled insights.
aws comprehend detect-sentiment \
--text "Artificial Intelligence is transforming the world in amazing ways!" \
--language-code en \
--region us-east-1[!TIP] The output will show a
Sentiment(e.g., POSITIVE) and aSentimentScorebreakdown for Positive, Negative, Neutral, and Mixed. This highlights how AI models deal with probability rather than absolute certainty.
▶Console alternative
- Navigate to the Amazon Comprehend Console.
- In the left sidebar, click Real-time analysis.
- Under Input text, paste:
Artificial Intelligence is transforming the world in amazing ways! - Click Analyze.
- Scroll down to the Insights tab and view the Sentiment results.
Teardown
[!WARNING] Remember to run the teardown commands to avoid ongoing charges. Leaving data in S3 incurs minor storage costs.
To clean up your AWS environment, empty and delete the S3 bucket, and remove your local file.
# Delete the image from the S3 bucket
aws s3 rm s3://brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>/sample-text.jpg
# Delete the S3 bucket
aws s3 rb s3://brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID>
# Remove the local file
rm sample-text.jpgTroubleshooting
| Common Error | Cause | Fix |
|---|---|---|
AccessDenied or InvalidAccessKeyId | Your AWS CLI is not configured correctly or your IAM user lacks permissions. | Run aws configure and ensure you are using an IAM user with AdministratorAccess or specific service policies. |
BucketAlreadyExists | S3 bucket names are globally unique. Someone else has used this name. | Change <YOUR_ACCOUNT_ID> to a random string of numbers/letters in Steps 1, 2, and 3. |
InvalidS3ObjectException in Rekognition | The bucket name or file name in the JSON string is incorrect. | Double-check the spelling of the bucket and ensure sample-text.jpg was successfully uploaded in Step 2. |
UnrecognizedClientException in Comprehend | Often caused by specifying an unsupported region. | Ensure you append --region us-east-1 (or another supported region) to your CLI command. |
Cost Estimate
- Amazon S3: First 50 TB/month is fractions of a cent per GB. Uploading one small image falls well within the AWS Free Tier.
- Amazon Rekognition: Free tier allows 1,000 images per month. Outside free tier, ~$0.001 per image.
- Amazon Comprehend: Free tier allows 50,000 units of text (100 characters per unit) per month. Outside free tier, ~$0.0001 per unit.
- Total Expected Cost: $0.00 (Assuming free tier eligibility or just a few cents otherwise).