Hands-On Lab940 words

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.

Compiling TikZ diagram…
Running TeX engine…
This may take a few seconds

Learning Objectives

By the end of this lab, you will be able to:

  1. Differentiate Data Types: Handle unstructured data (images and raw text) in an AI pipeline.
  2. Execute Real-Time Inferencing: Send single-request data to pre-trained foundation models and receive immediate predictions.
  3. Apply Computer Vision (CV): Use Amazon Rekognition to extract Optical Character Recognition (OCR) data from an image.
  4. 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.

Loading Diagram...

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).

bash
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
  1. Navigate to the S3 Console.
  2. Click Create bucket.
  3. Enter brainybee-lab-ai-concepts-<YOUR_ACCOUNT_ID> as the Bucket name.
  4. 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.

bash
# 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
  1. Download the image from this link to your computer.
  2. Navigate to your newly created S3 bucket in the console.
  3. Click Upload, select your downloaded sample-text.jpg, and click Upload.

Checkpoints

Let's verify our unstructured data is safely stored in S3.

bash
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.

bash
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 DetectedText and a Confidence score (a percentage indicating how certain the ML algorithm is about its prediction).

Console alternative
  1. Navigate to the Amazon Rekognition Console.
  2. In the left sidebar, choose Text in image.
  3. Expand the Upload dropdown and upload your local sample-text.jpg.
  4. 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.

bash
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 a SentimentScore breakdown for Positive, Negative, Neutral, and Mixed. This highlights how AI models deal with probability rather than absolute certainty.

Console alternative
  1. Navigate to the Amazon Comprehend Console.
  2. In the left sidebar, click Real-time analysis.
  3. Under Input text, paste: Artificial Intelligence is transforming the world in amazing ways!
  4. Click Analyze.
  5. 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.

bash
# 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.jpg

Troubleshooting

Common ErrorCauseFix
AccessDenied or InvalidAccessKeyIdYour 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.
BucketAlreadyExistsS3 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 RekognitionThe 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 ComprehendOften 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).

Ready to study AWS Certified AI Practitioner (AIF-C01)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free