Image Labels Generator with Rekognition
Analyze images with AWS Rekognition and visualize detected objects with bounding boxes.
Introduction
30 Second Summary
Your phone can search your photos for "beach" and instantly find every vacation picture. Behind that feature is image recognition technology that detects objects, people, and scenes in any image.
In this project, you will build an image labels generator powered by Amazon Rekognition. You'll upload a photo to Amazon S3, run a Python script, and watch Rekognition identify objects in the image and highlight them with colored bounding boxes.
What You'll Build
Upload any photo, run a single command, and watch your script print detected labels to the terminal while a popup window opens with colored boxes drawn around every identified object.
By the end of this project, you'll have:
- Upload any JPG or PNG image to S3 and get back detected labels like "Car", "Person", and "Tree" with confidence percentages.
- See bounding boxes drawn directly on the image, each labeled with the object name, in a popup window on your screen.
- Control how many labels Rekognition returns by adjusting MaxLabels in your script.
- Secret Mission: Add a minimum confidence filter so only labels above a chosen threshold appear in your output.
Are there any prerequisites?
No prior experience with AWS or Python is required. This project walks you through setting up every tool from scratch.
Before We Start
Before We Start...
Before we dive in, let's lock in what you're about to build and why it matters.
Set Up Your Tools
Your image labels generator needs a few tools before it can talk to AWS services. Python runs the script, the AWS CLI connects your terminal to your AWS account, and two Python libraries handle the API calls and image processing.
In this step, you will install all four tools and verify each one is ready to go.
In this step, get ready to:
- Install Python 3 and pip.
- Install the AWS CLI v2.
- Set up a project folder with boto3 and Pillow.
Install Python 3 and pip
The boto3 library (the AWS SDK for Python) requires Python 3.10 or higher. Most Linux distributions ship with Python 3, so let's check what you have.
- Open a terminal by pressing Ctrl+Alt+T.
- Check your Python version by running this command:
python3 --version
✔️ I see version 3.10 or higher
Python is ready. Move on to the next substep.
ⓧ I see an older version
Your system's Python is below 3.10, which means boto3 will not work correctly. Update Python through your package manager.
- On Ubuntu/Debian, update and install the latest available Python by running:
sudo apt update && sudo apt install python3 python3-pip python3-venv
- On Fedora, run:
sudo dnf install python3 python3-pip
- Run python3 --version again to confirm you now have 3.10 or higher.
Still below 3.10 after updating?
Some older Linux releases (like Ubuntu 20.04) cap Python at 3.8 in their default repositories. Visit python.org/downloads for the latest installer, or consider upgrading your distribution.
help me install Python 3.10 or higher on my Linux distribution
ⓧ Command not found
Python is not installed yet. Install it through your package manager.
- On Ubuntu/Debian, install Python by running:
sudo apt update && sudo apt install python3 python3-pip python3-venv
- On Fedora, install Python by running:
sudo dnf install python3 python3-pip
- Verify the installation by running:
python3 --version
You should see a version number of 3.10 or higher.
Install the AWS CLI v2
The AWS CLI lets you manage AWS services directly from your terminal. You will use it in the next step to configure your credentials, and later to create S3 buckets and upload images.
- Download and install the AWS CLI by running these commands:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
What do these commands do?
- curl downloads the official AWS CLI installer as a zip file.
- unzip extracts the installer files from the zip archive.
- sudo ./aws/install runs the installer with admin privileges. Your terminal will ask for your password.
- Verify the installation by running:
aws --version
You should see a version string starting with aws-cli/2 followed by version details.
Seeing command not found?
- If unzip is not found, install it first with sudo apt install unzip (Ubuntu/Debian) or sudo dnf install unzip (Fedora), then re-run the three commands above.
- If aws is not found after installing, close your terminal and open a new one so your system picks up the new path.
help me troubleshoot my AWS CLI installation on Linux
Install boto3 and Pillow
Pillow is a Python imaging library that draws shapes and text onto images. Together with boto3, these two libraries power your script's ability to call Amazon Rekognition and visualize the results.
- Move to your Desktop and create your project folder by running these commands:
cd ~/Desktop
mkdir rekognition-labels
cd rekognition-labels
- Confirm you are in the right folder by running:
pwd
You should see a path ending in Desktop/rekognition-labels.
Before installing packages, you will create a virtual environment. This keeps the project's libraries separate from your system Python so they do not interfere with other projects on your machine.
- Create and activate a virtual environment by running:
python3 -m venv .venv
source .venv/bin/activate
What is a virtual environment?
A virtual environment is an isolated copy of Python with its own set of installed packages. When you activate it, your terminal uses the virtual environment's Python and pip instead of your system-wide ones.
The .venv folder inside rekognition-labels holds everything. If you ever want a fresh start, just delete that folder and create it again.
Your terminal prompt should now start with (.venv). This confirms the virtual environment is active.
Don't see (.venv) in your prompt?
- Make sure you ran source .venv/bin/activate (not just the python3 -m venv line). The first command creates the environment. The second command activates it.
- If you see an error about python3-venv not being installed, run sudo apt install python3-venv and try again.
help me activate my Python virtual environment on Linux
- Install boto3 and Pillow by running:
pip install boto3 pillow
Before you verify, what two package names do you expect to see in the output?
- Verify both packages are installed by running:
pip list | grep -i -E "boto3|pillow"
You should see boto3 and Pillow listed with version numbers next to each one.
Not seeing both packages?
- Check that your virtual environment is still active. You should see (.venv) at the start of your prompt. If not, re-activate it with source .venv/bin/activate and re-run the install command.
- If the install failed with a permissions error, make sure you are using the virtual environment's pip (not the system one). Run which pip to check. It should point to a path inside .venv/.
help me install boto3 and Pillow in my virtual environment
Your tools are ready. Next up, you will create an IAM user so your Python script can securely access AWS services.
Create an IAM User and Configure the AWS CLI
Your tools are installed and your project folder is ready. Now your Python script needs an identity to access AWS services.
Every AWS API call must come from an authenticated identity. In this step, you'll create a dedicated IAM user, give it the right permissions, and connect those credentials to the AWS CLI on your machine.
In this step, get ready to:
- Create an IAM user with permissions for Rekognition and S3.
- Generate an access key for programmatic access.
- Configure the AWS CLI with your new credentials.
Create an IAM user with programmatic access
IAM users let you control who can access your AWS resources and what they can do. You'll create a dedicated user for this project with just the permissions it needs.
- Open your browser and navigate to the AWS Management Console.
- Sign in with your AWS account.
Need an AWS account?
Create a free account at aws.amazon.com. New accounts receive up to $200 in Free Tier credits, which covers this project's costs.
- In the search bar at the top of the console, type IAM and select IAM from the results.
- In the left sidebar, click Users.
- Click Create user.
- Enter rekognition-user in the User name field.
- Click Next.
What is IAM?
IAM (Identity and Access Management) is the AWS service that controls who can access your AWS resources. Each IAM user has its own credentials and specific permissions.
By creating a dedicated user for this project, you keep your root account secure and limit access to only the services your script needs.
- Select Attach policies directly.
- Type AmazonRekognitionFullAccess in the policy search box.
- Check the box next to AmazonRekognitionFullAccess.
- Clear the search box and type AmazonS3FullAccess.
- Check the box next to AmazonS3FullAccess.
What do these policies control?
AmazonRekognitionFullAccess allows the user to call any Amazon Rekognition API, including DetectLabels. AmazonS3FullAccess allows the user to create buckets, upload files, and read objects in Amazon S3.
Together, they give your script everything it needs for this project.
- Click Next.
- Click Create user.
Your new user now appears in the Users list. You should see rekognition-user listed.
Don't see your user?
- Make sure you clicked Create user on the final review page.
- Refresh the Users page in the IAM console.
- Help me troubleshoot creating an IAM user in the AWS console.
Create an access key for your IAM user
An access key is a pair of credentials (a key ID and a secret key) that lets programs authenticate with AWS. Your Python script and the AWS CLI both use this access key to prove they are acting as your IAM user.
- Click on rekognition-user in the Users list.
- Click the Security credentials tab.
- Scroll down to Access keys and click Create access key.
- Select Command Line Interface (CLI) as the use case.
- Check the confirmation checkbox at the bottom of the page.
- Click Next.
- Click Create access key.
Your access key pair is now displayed on screen.
- Copy the Access Key ID and save it somewhere secure, like a text file or password manager.
- Copy the Secret Access Key and save it in the same secure location.
Save your credentials now
The Secret Access Key is only shown once. If you close this page without saving it, you will need to create a new access key.
Never share your access keys or commit them to version control.
Configure the AWS CLI with your credentials
The AWS CLI needs your IAM user's credentials to authenticate API calls. The aws configure command stores them locally on your machine so every CLI command uses them automatically.
- Switch back to your terminal and start the CLI configuration by running this command:
aws configure
What will this command ask?
The aws configure command prompts you for four values one at a time. You'll enter your access key ID, secret access key, default region, and output format. Each value is saved in a credentials file on your machine.
- When prompted for your access key ID, paste the Access Key ID you saved earlier.
- When prompted for your secret access key, paste the Secret Access Key you saved earlier.
- When prompted for the default region name, enter us-east-1.
- When prompted for the default output format, enter json.
Before you run the next command, what do you think it will return if your credentials are configured correctly?
- Verify your configuration by running this command:
aws sts get-caller-identity
You should see a JSON response containing your AWS account ID and the ARN of your rekognition-user. This confirms the CLI is authenticated as your IAM user.
Seeing an error?
- If you see a message about being unable to locate credentials, run aws configure again and double-check that you pasted the full access key ID and secret access key.
- If your access key is reported as invalid, verify that the access key is active in the IAM console under your user's Security credentials tab.
- Help me troubleshoot my aws sts get-caller-identity error.
Your AWS identity is set up and your CLI is connected. Next up, you'll create an S3 bucket and upload an image for Rekognition to analyze.
Upload an Image to S3
Your AWS credentials are locked in. The CLI knows who you are and which services you can access.
Amazon Rekognition's DetectLabels API reads images directly from Amazon S3 buckets. Before Rekognition can analyze anything, you need a bucket to store your image in the cloud.
What is Amazon S3?
S3 (Simple Storage Service) is AWS's cloud object storage. Think of it like a folder in the cloud where you can store any type of file.
Each storage container in S3 is called a bucket. Every bucket has a globally unique name, meaning no two AWS accounts in the entire world can share the same bucket name.
In this step, get ready to:
- Create an S3 bucket to store your images.
- Upload a test image to the bucket and verify it arrived.
Create an S3 bucket
S3 bucket names are globally unique across all AWS accounts. You need to pick a name that nobody else in the world has used.
- Create your S3 bucket by running this command:
aws s3 mb s3://[[BUCKET_NAME="rekognition-labels-yourname-2026"]] --region us-east-1
What does this command do?
- aws s3 mb stands for "make bucket." It creates a new S3 bucket with the name you provide.
- --region us-east-1 places the bucket in the US East (N. Virginia) region. This must match the region you'll use for Rekognition later.
- Replace "yourname" with something unique to you, like your first name or initials. For example, rekognition-labels-alex-2026.
- Confirm your bucket was created by running:
aws s3 ls
You should see your new bucket name listed in the output with today's date.
Why does the bucket region matter?
The region for your S3 bucket must match the region you use for Rekognition API calls. Both are set to us-east-1 in this project. If they don't match, Rekognition won't be able to find your image.
Bucket creation failed?
- If you see an error mentioning BucketAlreadyExists, the name is taken by another AWS account. Try adding extra numbers or your initials to make it unique.
- If you see an access denied error, make sure your IAM user has the AmazonS3FullAccess policy attached.
- Bucket names can only contain lowercase letters, numbers, and hyphens. No uppercase letters or spaces.
Why can't I create my S3 bucket?
Upload a test image to your bucket
Rekognition works best when the image has clear, recognizable objects. You need a JPG or PNG file with things like people, cars, or animals in it.
- Find or download a JPG or PNG image that contains multiple recognizable objects (people, vehicles, animals, furniture, etc.).
- Save the image file into your rekognition-labels folder on the Desktop.
Image requirements
Rekognition supports PNG and JPEG formats only. The image must be under 15 MB when stored in S3. A regular photo from your phone or a free stock photo site works perfectly.
- Upload your image to S3 by running this command:
aws s3 cp [[IMAGE_FILE="your-image.jpg"]] s3://[[BUCKET_NAME="rekognition-labels-yourname-2026"]]/
What does this command do?
- aws s3 cp copies a file from your local machine to S3 (or vice versa). It works like a regular copy command, but one end is the cloud.
- The first argument is your local file. The second argument is the S3 destination, ending with / to place the file inside the bucket.
Before you run the next command, what do you expect to see listed inside your bucket?
- Check that your image made it to S3 by running:
aws s3 ls s3://[[BUCKET_NAME="rekognition-labels-yourname-2026"]]/
Your image file appears in the listing with its file size and upload date. This confirms the image is in the cloud and ready for Rekognition to analyze.
Don't see your image?
- If you see an error mentioning the path does not exist, double check that the image file is saved inside your rekognition-labels folder and that you typed the file name exactly as it appears (including the extension).
- Make sure your bucket name in the command matches the name you used when creating the bucket. Typos or extra characters will point to a non-existent bucket.
- Run ls in your terminal to confirm the image file is in your current directory.
Why isn't my image uploading to S3?
Your image is in the cloud and waiting to be analyzed. Next up, you'll write the Python script that sends this image to Rekognition and gets back a list of everything it detects.
Write the Label Detection Script
Your S3 bucket is loaded with a test image, and your AWS CLI credentials are ready to go.
Now it is time to write the core of the project. Your Python script will connect to Amazon Rekognition, send it a reference to your S3 image, and get back a list of detected labels with confidence scores. The output in this step is text only. You will see label names printed to the terminal, but no visual feedback showing where those objects sit in the image.
In this step, get ready to:
- Create a Python script that calls Rekognition's DetectLabels API.
- Print detected labels with confidence scores and bounding box data to the terminal.
Create the detection script
Your script needs two things: configuration values that point to your S3 bucket and image, and a function that sends those values to Rekognition.
- Make sure your virtual environment is still active in your terminal. You should see (.venv) at the start of your prompt. If not, activate it by running:
source .venv/bin/activate
- Create a new file called detect_labels.py in your rekognition-labels folder by running:
touch detect_labels.py
- Confirm the file was created by running:
ls
You should see detect_labels.py listed alongside your .venv folder.
- Open detect_labels.py in your text editor and add the imports, configuration, and core detection function by copying this code:
import boto3
import io
from PIL import Image, ImageDraw, ImageFont
# Configuration
BUCKET = "[[BUCKET_NAME=\"rekognition-labels-yourname-2026\"]]"
PHOTO = "[[IMAGE_FILE=\"your-image.jpg\"]]"
MAX_LABELS = 10
REGION = "us-east-1"
def detect_labels(bucket, photo, max_labels):
"""Call Rekognition DetectLabels and return the response."""
# Create a Rekognition client in the same region as your S3 bucket
client = boto3.client("rekognition", region_name=REGION)
# Send the S3 image reference to Rekognition
response = client.detect_labels(
Image={"S3Object": {"Bucket": bucket, "Name": photo}},
MaxLabels=max_labels,
)
return response
What does this code do?
The top section imports boto3 (the AWS SDK for Python) and sets up four configuration constants. BUCKET and PHOTO point to your S3 image. MAX_LABELS caps how many labels Rekognition returns. REGION must match your S3 bucket's region.
The detect_labels() function creates a Rekognition client and calls detect_labels() with an S3 object reference. Rekognition reads the image directly from S3 and returns the full response, including label names, confidence scores, and bounding box coordinates.
The io, Image, ImageDraw, and ImageFont imports are not used yet. You will use them in the next step to draw bounding boxes on the image.
The script is not runnable yet because there is no entry point. Time to add the output formatting and the main() function.
- Below the detect_labels() function, add the print_labels() function, the main() entry point, and the script runner by copying this code:
def print_labels(response, photo):
"""Print detected labels and their confidence to the terminal."""
print(f"Detected labels for {photo}")
print()
for label in response["Labels"]:
# Print each label name with its confidence percentage
print(f" {label['Name']}: {label['Confidence']:.2f}%")
# Print bounding box coordinates for labels with detected instances
for instance in label["Instances"]:
box = instance["BoundingBox"]
print(f" Bounding box: Left={box['Left']:.4f}, Top={box['Top']:.4f}, "
f"Width={box['Width']:.4f}, Height={box['Height']:.4f}")
print()
print(f"Labels detected: {len(response['Labels'])}")
def main():
response = detect_labels(BUCKET, PHOTO, MAX_LABELS)
print_labels(response, PHOTO)
if __name__ == "__main__":
main()
What does this code do?
The print_labels() function loops through the Labels array in the Rekognition response. For each label, it prints the name and confidence score. If a label has Instances (physical objects like cars or people), it also prints the BoundingBox coordinates. Abstract labels like "Transportation" or "Nature" do not have bounding boxes.
The BoundingBox values are normalized between 0 and 1. They represent fractions of the image width and height, not pixel positions. You will convert these to pixel coordinates in the next step when you draw the boxes.
The main() function ties everything together, and the if __name__ == "__main__" block ensures the script runs when you execute it directly.
- Save detect_labels.py.
✔️ Awesome, I've got everything!
Great. Double check you have saved detect_labels.py and move on to the next substep to run it.
ⓧ I'd like to double check the full code
Scroll up and confirm your detect_labels.py file contains these sections in order:
- Imports (boto3, io, Image, ImageDraw, ImageFont).
- Configuration constants (BUCKET, PHOTO, MAX_LABELS, REGION).
- The detect_labels() function that calls Rekognition.
- The print_labels() function that formats the output.
- The main() function and the if __name__ == "__main__" entry point.
Make sure BUCKET matches your actual S3 bucket name and PHOTO matches your uploaded image filename.
File not saving?
Make sure you are editing the file inside the rekognition-labels folder. Run pwd to confirm your current directory.
Help me troubleshoot my file
Run the script
Your script is complete. Before you run it, think about what you expect to see. Will every label come with bounding box coordinates, or only some of them?
- Run the detection script by executing:
python3 detect_labels.py
You should see a list of detected labels printed to the terminal, each with a confidence percentage. Something like this:
Detected labels for your-image.jpg
Car: 99.15%
Bounding box: Left=0.0038, Top=0.5039, Width=0.1062, Height=0.1853
Person: 98.99%
Bounding box: Left=0.3604, Top=0.0925, Width=0.2680, Height=0.8560
Transportation: 99.15%
Road: 76.85%
Labels detected: 10
Notice that labels for physical objects (like "Car" or "Person") include bounding box data. Abstract labels (like "Transportation" or "Road") do not.
The bounding box numbers are there in the terminal output, but they are just raw decimal values. There is no way to see where those boxes sit on the actual image yet.
What are those bounding box numbers?
Rekognition returns bounding box coordinates as normalized values between 0 and 1. Left and Top mark the top-left corner of the box as a fraction of the image width and height. Width and Height describe the box size the same way.
For example, Left=0.36 means the box starts 36% from the left edge of the image. To draw these on the actual image, you need to multiply by the pixel dimensions. That is exactly what you will do in the next step.
Seeing an error?
- If you see an access denied or credentials error, make sure your AWS CLI is configured with the correct access key. Run aws sts get-caller-identity to verify.
- If you see a bucket or key not found error, double check that BUCKET and PHOTO in your script match your actual S3 bucket name and image filename exactly.
- If you see a module not found error for boto3 or PIL, make sure your virtual environment is activated. You should see (.venv) in your terminal prompt.
Help me debug this error
Your script is pulling real results from Rekognition and printing them to the terminal. Next up, you will turn those raw bounding box numbers into colored rectangles drawn directly on the image.
Add Bounding Box Visualization
In Step 4, you ran your script and saw Amazon Rekognition identify objects in your image. Labels like "Car" and "Person" appeared in the terminal with confidence scores.
Those labels tell you what Rekognition found, but not where each object sits in the image. Rekognition actually returns bounding box coordinates for many detected objects. In this step, you will download the image from S3, convert those coordinates into pixel positions, and draw colored rectangles around each detected object using Pillow.
In this step, get ready to:
- Add a function that downloads the image from S3 and draws bounding boxes using Pillow.
- Update the main function to call the new visualization code.
- Run the script and see a popup window with labeled bounding boxes on your image.
Add the draw_bounding_boxes function
Rekognition returns bounding box coordinates as normalized values between 0 and 1. These represent fractions of the image's total width and height.
To draw rectangles on the actual image, you need to multiply these fractions by the image's pixel dimensions. Your script will download the image from S3 into memory, then use Pillow's drawing tools to place a red box and label at each detected object's location.
- The imports you need (boto3, io, Image, ImageDraw) are already at the top of your file from Step 4.
- In detect_labels.py, find the main() function. Add this new function directly above main():
def draw_bounding_boxes(response, bucket, photo):
"""Download image from S3 and draw bounding boxes on detected objects."""
s3_client = boto3.client("s3", region_name=REGION)
s3_response = s3_client.get_object(Bucket=bucket, Key=photo)
image_bytes = s3_response["Body"].read()
image = Image.open(io.BytesIO(image_bytes))
img_width, img_height = image.size
draw = ImageDraw.Draw(image)
for label in response["Labels"]:
for instance in label["Instances"]:
box = instance["BoundingBox"]
left = img_width * box["Left"]
top = img_height * box["Top"]
width = img_width * box["Width"]
height = img_height * box["Height"]
draw.rectangle(
[left, top, left + width, top + height],
outline="red",
width=3,
)
draw.text(
(left, top - 15),
f"{label['Name']} ({instance['Confidence']:.1f}%)",
fill="red",
)
image.show()
What does this code do?
- s3_client.get_object() downloads your image from S3 as raw bytes, so you never need a local copy of the file.
- Image.open(io.BytesIO(image_bytes)) converts those raw bytes into a Pillow image object you can draw on.
- The nested loop walks through every label that has Instances. Not every label has bounding box data. Abstract labels like "Nature" or "Transportation" describe the whole scene, so they have no box coordinates.
- Multiplying the normalized coordinates (0 to 1) by img_width and img_height converts them to actual pixel positions on the image.
- draw.rectangle() draws a red border around the detected object. draw.text() writes the label name and confidence just above each box.
- image.show() opens the annotated image in your system's default image viewer as a popup window.
- Save detect_labels.py. The function is ready. The next chunk connects it to main().
Update main() to call the new function
The draw_bounding_boxes function exists but nothing calls it yet. You need to wire it into main() so it runs every time the script executes.
- In detect_labels.py, scroll down to the main() function.
- Find this line:
print_labels(response, PHOTO)
- Add the following line directly below it, so main() now looks like this:
def main():
response = detect_labels(BUCKET, PHOTO, MAX_LABELS)
print_labels(response, PHOTO)
draw_bounding_boxes(response, BUCKET, PHOTO)
What does this change do?
The new line passes the Rekognition response, your bucket name, and the photo key to draw_bounding_boxes(). That function downloads the image, draws the boxes, and pops open the viewer. The order matters: labels print to the terminal first, then the image opens.
- Save detect_labels.py.
Run the script and verify the bounding boxes
Before you run the script, think about what you expect to see differently from the last time you ran it. Will the terminal output change? Will something new appear?
- Make sure your virtual environment is still activated in your terminal (you should see (.venv) at the start of your prompt).
- Run the script by executing this command:
python3 detect_labels.py
The same list of labels and confidence scores prints to the terminal. Then a popup window opens showing your original image with red rectangles drawn around each detected object. Each rectangle has the object name and confidence percentage written just above it.
Why don't all labels have bounding boxes?
You may notice more labels in the terminal output than rectangles on the image. Only labels with localized, physical objects (like "Car" or "Person") get bounding box coordinates. Abstract labels (like "Transportation" or "Nature") describe the overall scene and have no specific location, so they appear in the terminal list but not on the image.
No popup window appearing?
- Make sure your Linux machine has a desktop environment running. image.show() relies on a display manager to open the image viewer. If you are on a headless server, you can add image.save("output.jpg") instead of image.show() to save the annotated image to disk.
- Check that the BUCKET and PHOTO values at the top of your script match your actual S3 bucket name and image file name exactly.
- If you see a permissions error, confirm that your IAM user still has the AmazonS3FullAccess policy attached. The new function downloads the image from S3, which requires read access.
Help me debug why my bounding box image isn't showing up after running detect_labels.py.
✔️ Awesome, I've got everything!
Great. Double check you have saved detect_labels.py.
ⓧ I'd like to double check the full code
Scroll up through your detect_labels.py file and confirm each of these sections is present, in order:
- Imports at the top: import boto3, import io, and from PIL import Image, ImageDraw, ImageFont.
- Configuration block: BUCKET, PHOTO, MAX_LABELS, and REGION.
- detect_labels() function: calls Rekognition and returns the response.
- print_labels() function: prints labels, confidence scores, and bounding box data to the terminal.
- draw_bounding_boxes() function: downloads the image from S3, draws red rectangles and label text, and calls image.show().
- main() function: calls all three functions in order: detect_labels(), print_labels(), then draw_bounding_boxes().
- if __name__ == "__main__" block: at the very bottom, calling main().
Your script now gives you both a text readout and a visual proof of what Rekognition detected. Next up, the Secret Mission challenges you to add a confidence threshold filter so you can control which labels make the cut.
Secret mission
Add a Confidence Threshold Filter
Rekognition returns many labels with varying confidence levels. Some detections are strong, while others are just educated guesses. Can you add a minimum confidence filter so only the most meaningful detections make it through?
Clean Up Your Resources
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely. This project uses minimal AWS resources. The S3 bucket costs fractions of a cent per month for a few images, and Rekognition charges $0.001 per image only when you run the script.
Cost warning
While ongoing costs are negligible, the IAM user's access keys remain active until you deactivate or delete them. If you are done with this project, delete the access keys and IAM user to avoid any security risk from unused credentials.
Resources you used:
- S3 bucket rekognition-labels-yourname-2026 containing your test image.
- IAM user rekognition-user with access keys and attached policies.
- AWS CLI credentials stored in ~/.aws/.
- Local project folder rekognition-labels on your Desktop with the virtual environment and script.
Keep everything running
No action needed. Choose this if you are still actively building or want to experiment with different images and settings.
- Your S3 bucket stores a few images at negligible cost.
- Rekognition only charges when you run the script, so there is no idle cost.
- The AWS CLI and your local project folder remain on your machine for future use.
Pause - I'll come back to this later
Shut down running processes to free up resources while keeping your files and AWS setup intact.
- Deactivate your access key to prevent accidental use. In the IAM console, choose Users, select rekognition-user, open the Security credentials tab, find your key in the Access keys section, choose Actions, then choose Deactivate.
- Deactivate your virtual environment by running:
- Your S3 bucket and local files stay in place. You can reactivate the access key and virtual environment when you return.
deactivate
Delete - I don't want to use this again
Remove all project resources and start fresh. Follow each step below.
- Delete the S3 bucket and all its contents by running:
aws s3 rb s3://[[BUCKET_NAME="rekognition-labels-yourname-2026"]] --force
- Delete the IAM user's access key. In the IAM console, choose Users, then select rekognition-user. Open the Security credentials tab. In the Access keys section, choose Actions, then choose Deactivate. After deactivating, choose Actions again, then choose Delete. Confirm the deletion in the dialog.
- Delete the IAM user. Return to the Users list in the IAM console. Select the checkbox next to rekognition-user and choose Delete. Confirm the deletion by typing the user name when prompted.
- Remove the AWS CLI credentials stored on your machine by running:
rm -rf ~/.aws/
Heads up
The ~/.aws/ folder stores credentials and config shared across all AWS SDKs and the AWS CLI. Only delete it if you have no other AWS projects on this machine.
- Delete the local project folder by running:
rm -rf ~/Desktop/rekognition-labels
- Clean up the AWS CLI installer files left over from setup by running:
rm -rf ~/Desktop/awscliv2.zip ~/Desktop/aws
Nice Work!
Nice Work!
You just built an image labels generator powered by Amazon Rekognition. You can now upload any photo to S3, run a single Python script, and see exactly what Rekognition detects, complete with labeled bounding boxes drawn right on the image.
You've learned how to:
- Set up the AWS CLI and configured IAM credentials for programmatic access to AWS services.
- Created an S3 bucket and uploaded images for cloud-based analysis with Amazon Rekognition's DetectLabels API to identify objects, scenes, and concepts in images.
- Used Pillow to draw bounding boxes around detected objects and display them visually in a popup window.
- (Secret Mission) Added a confidence threshold filter to control which labels appear in the output.
Ready to quiz yourself?